Skip to main content

Posts

Showing posts with the label multithreading

Is there a way to set a Web Worker to low priority?

I am thinking of using Web Workers to provide some background functionality while a user is browsing my website (that's what Web Workers are for, right?). However, I don't want to take the risk of compromising the user experience by causing laggy scrolling, unresponsive controls, etc. Web Workers are mapped on OS threads, hence I would expect some control on the priority of these threads however, as far as I know, there's no such thing in the current API. Do you know a how to accomplish this? Even with a hack?

Are Java static initializers thread safe?

I'm using a static code block to initialize some controllers in a regsitry I have. My question is therefore, can I guarantee that this static code block will only absolutely be called once when the class is first loaded? I understand I cannot guarantee when this code block will be called, Im guessing its when the Classloader first loads it. I realize I could synchronize on the class in the static code block, but my guess is this is actually what happens anyway? Simple code example would be; class FooRegistry { static { //this code must only ever be called once addController(new FooControllerImpl()); } private static void addController(IFooController controller) { // ... } } or should I do this; class FooRegistry { static { synchronized(FooRegistry.class) { addController(new FooControllerImpl()); } } private static void addController(IFooController controller) { // ... } }

How to make a Java thread wait for another thread"s output?

I'm making a Java application with an application-logic-thread and a database-access-thread. Both of them persist for the entire lifetime of the application. However, I need to make sure that the app thread waits until the db thread is ready (currently determined by calling dbthread.isReady() ). I wouldn't mind if app thread blocked until the db thread was ready. Thread.join() doesn't look like a solution - the db thread only exits at app shutdown. while (!dbthread.isReady()) {} kind of works, but the empty loop consumes a lot of processor cycles. Any other ideas? Thanks.

Android Thread Concurrent running threads notify between them

I want to execute the method uploadingDone() after completion of all three threads. The flags are working most of time correct. In rare case all three flags set to true and BLOCK1 get executed twice. All three threads are doing different tasks on different data ( No Concurrent modification can occur). Can I eliminate the flags with any native function on thread? All three threads to be run in parallel(Mandatory Requirement.). BLOCK1 should be called only once . private synchronized void uploadingDone(){ if( isItemUploaded && isListUploaded && isStoreUploaded){ uploadingDone = true; //<BLOCK1> //TODO move to next screen }else{ Log.i(TAG, "uploadingDone: Failed"); } } private boolean isListUploaded = false, isItemUploaded = false, isStoreUploaded = false, uploadingDone = false; private class ListUpload extends Thread{ @Override public void run() { isListUploaded = true; Log.i(TAG

Create a stuck thread (Weblogic)(J2SE)(1.5)

I need to test WLST script that checks for stuck threads across some managed instances on a weblogic deployment. Unfortunately when I need to test, I am unable to get my stuck thread problem to rear its head. How can I intentionally create a stuck thread to test my script's detection with? My thoughts presently have been to sleep a thread for more than my stuck thread limit on Weblogic's settings, but that is also longer than the timeout for webpages. So my request should timeout before the thread ever becomes stuck. Apache commons executor is another idea... Does anyone have an elegant solution to reproducing this ugly issue?

Multithreading in Java Help Needed

Before I go any further, this IS apart of my homework.The part that I am having trouble with however, is not the main point of the assignment. For the assignment we are just storing numbers in an array, and am adding up the elements of the array via multithreading. The user enters how many threads that they would like to run, and what the upper bound should be. For example: Upper Bound: 12 Threads: 2 The application should add up elements 1-6, then 7-12. In this case the lower bound starts out at 1 and the upper bound starts out at 6. Then the second time the loop should itterate the upper bound should be 7 and the upper bound should be 12. I am having trouble trying to devide the upper bound by the number of threads to create the increments in wich the lower and upper bounds are based off of. It is fairly simple if the number of threads devides evenly into the starting upper bound. But when It doesn't is when I am having the problem. Thank You!

Android - Running heavy computations in background and returning the result to an Activity

I have implemented some computationaly heavy functions into my application. Depending on the type of input it can take up to several minutes for a thread to return. During this time, I want the user to be able to work with other activities to perform different tasks (i.e. prepare data for the next run). Then, after the Service has finished it's computations, the user should be notified with a Toast that the result is ready and that he should check back to the Activity he started the Service in. Unfortunately I'm stuck at this point. Is it possible to somehow communicate with an Activity which is destroyed at the moment? Like modifying the saved state, so that when it get's recreated the result will be displayed. The only way of communication I did find was via broadcasting from the Service, but this requires the Activity to listen, which is not possible as it doesn't exist at the moment the Service finishes. The only solution that occured to me was writing a file

updated gui application

I need to write an application that will check for something every X time and update it to GUI comtols. I have some little knowledge in java and written some applications before but I've never dealt with stuff like multiple threads and updating the GUI. I though it will be an easy task so I've started to write my software. Everything else is pretty much functioning. I just cant get the app to perform checks every X time and then update the GUI. Can someone please give some guidance on this? What shold I look into? what is the common practice? Is it threads? recursive? anything else? Also if possible provide me some code examples, I can understand better. thanks for any effort!

ThreadPoolExecutor for running AbortableHttpRequest - how to call abort?

I'm running a networking service in android where I direct all my http requests to run and get callbacks from the service when the requests are complete. I run the requests in a ThreadPoolExecutor to limit the number of concurrent requests. As the requests run within the pool, they eventually create an HttpGet or HttpPost, both of which indirectly implement AbortableHttpRequest , which allows one to cancel the connection (say, if it's blocking for a long time). If a user cancels a request, I'd like to somehow drill into the thread queue and call the abort routine for that request. If, for example, a web site is not responding and the user chooses to do something else, right now my only option is to wait for the standard 5 minute http timeout to occur for that hung request before that thread is freed up. If I could access the thread that has my request and call abort, that would free things up right away. From what I can understand, it appears once my request has gon

PHP-CURL curl_multi_exec is it really multithreaded internally?

My question is very simple as stated in title. However I rephrase it again. I want to download multiple sites using php-curl. I'll run it from console. I am going to use curl_multi_exec to download all the sites. Now the question, will curl create different threads for each of the request? I know I can achieve it by forking multiple processes. But thats not threading. I dont want threading. I want to know if its multi-threaded?