multithreading

Android: CalledFromWrongThreadException from WebView's shouldOverrideUrlLoading

狂风中的少年 提交于 2020-01-16 00:54:24
问题 I am developing on a library that is somehow getting a CalledFromWrongThread Exception crash on Samsung Galaxy S1 (api v7 - android 2.1). The code is something like this: class MyWebViewClient extends WebViewClient { @Override public void shouldOverrideUrlLoading(WebView view, String url) { someListener.addToUiView(); } } and of course, the method that is actually throwing the error (which implements a listener callback): View v; public void addToUiView(){ v.addView(new TextView(context)); //

Customizing a name of a thread in camel

天涯浪子 提交于 2020-01-16 00:50:09
问题 How do I customise a thread name of a particular component in Apache Camel? 回答1: See http://camel.apache.org/threading-model.html: <camelContext xmlns="http://camel.apache.org/schema/spring" threadNamePattern="Riding the thread #counter#"> <route> <from uri="seda:start"/> <to uri="log:result"/> <to uri="mock:result"/> </route> </camelContext> 回答2: Thanks for your reply peter.I want to know how do i customise a thread name for particular component? For Ex: <camelContext threadNamePattern=

“Core Data could not fulfill a fault” for objects that were created in the appDelegate managedObjectContext on the main thread

笑着哭i 提交于 2020-01-16 00:43:06
问题 I mistakenly created a group of objects on a background thread, which created a new managedObjectContext in which the objects were saved. This resulted in numerous "Core Data could not fulfill a fault" crashes in my live app. Please note - I am not trying to delete these objects - it is a problem with the way they were created, when I try to save them again afterwards in the app delegate (main) context on the main thread. The thing that is confusing is that I am seeing this error for other

Why is this causing an ArgumentOutOfRangeException when using Parallel.For?

Deadly 提交于 2020-01-15 23:45:22
问题 I have had a go at writing something to hash numbers and check them against a list to see if a matching hash exists or not. I got this working fine using a for loop, I then decided to try speed things up by using Parallel.For - unfortunately this causes an ArgumentOutOfRangeException that i'm having trouble debugging. public class HashCompare { private string encryptedCardNumber; private Encrypter encrypter; private BlockingCollection<string> paraCardNumberList; public string Compare(string

How to control a Thread via input()?

南笙酒味 提交于 2020-01-15 23:04:28
问题 I want to run a code with process parallel to my main code but also want to access its parameters or start/stop the process via command prompt. my machine is win7 64bit. Something in mind is: from multiprocessing import Process class dllapi(): ... def apiloop(params, args): apiclient = dllapi(**args) while True: apiclient.cycle() params = [....] def mainloop(args): p = Process(target = apiloop, args=(params, args, )) while True: cmd = input() if cmd == 'kill': p.terminate() if cmd == 'stop':

What are the important threading API calls to understand before writing multi-threaded code?

你离开我真会死。 提交于 2020-01-15 20:19:11
问题 Recently I was blogging about the oft over-used idea of multi-threading in .Net. I put together a staring list for "APIs you should know first": Thread ThreadPool ManualResetEvent AutoResetEvent EventWaitHandle WaitHandle Monitor Mutex Semaphore Interlocked BackgroundWorker AsyncOperation lock Statement volatile ThreadStaticAttribute Thread.MemoryBarrier Thread.VolatileRead Thread.VolatileWrite Then I started thinking maybe not all of these are important. For instance, Thread.MemoryBarrier

Synchronizing two threads

一笑奈何 提交于 2020-01-15 19:15:50
问题 I have two threads and I want the second thread to wait until first thread finishes. How can I accomplish this? This my code: public class NewClass1 implements Runnable { // in main CallMatlab c = new CallMatlab(); CUI m = new CUI(); Thread t1 = new Thread(c); t1.start(); Thread t2 = new Thread(m); try { t1.join(); } catch (InterruptedException ex) { Logger.getLogger(NewClass1.class.getName()).log(Level.SEVERE, null, ex); } t2.start(); // public void run() { throw new

Synchronizing two threads

别说谁变了你拦得住时间么 提交于 2020-01-15 19:11:59
问题 I have two threads and I want the second thread to wait until first thread finishes. How can I accomplish this? This my code: public class NewClass1 implements Runnable { // in main CallMatlab c = new CallMatlab(); CUI m = new CUI(); Thread t1 = new Thread(c); t1.start(); Thread t2 = new Thread(m); try { t1.join(); } catch (InterruptedException ex) { Logger.getLogger(NewClass1.class.getName()).log(Level.SEVERE, null, ex); } t2.start(); // public void run() { throw new

rabbitmq queues filling up with celery tasks

社会主义新天地 提交于 2020-01-15 18:48:30
问题 I am using Celery to call multiple hardware units by their ip address. Each unit will return a list of values. Application code below # create a list of tasks modbus_calls = [] for site in sites: call = call_plc.apply_async((site.name, site.address), expires=120) # expires after 2 minutes? modbus_calls.append(call) # below checks all tasks are complete (values returned), then move forward out of the while loop ready_list = [False] while not all(ready_list): ready_list = [] for task in modbus

Kivy: Starting and Stopping Threads When Button is Clicked

风格不统一 提交于 2020-01-15 15:43:09
问题 I'm having trouble with the threading in Python and Kivy. I'm trying to implement threading in my kivy app. Basically, when I click a button and the screen switches to the next one, I want to launch a thread, and when I click the 'back' button, the thread should stop. It's a pretty simple task, but my current code doesn't end the thread once I pressed 'back'. Here is my code. I'm only including the necessary parts: KV: <MenuScreen>: canvas.before: Rectangle: pos: self.pos size: self.size