multithreading

Graceful shutdown of threads and executor

The following piece of code tries to accompolish this. The code loops forever and checks if there are any pending requests to be processed. If there is any, it creates a new thread to process the request and submits it to the executor. Once all the threads are done,it sleeps for 60 seconds and again checks for pending requests. public ...

Thread.sleep() doesn't strike when expected

I'm wondering why Thread.sleep() does not strike in the expected point of time. I expected the first rectangle to be drawn, a pause of 2 seconds and then the appearance of the second rectangle. However, the pause kicks in first and then both rectangles are drawn 'at once'. Why does this happen to be the case? Thanks in advance for any...

How to cancel waiting in select() on Windows

In my program there is one thread (receiving thread) that is responsible for receiving requests from a TCP socket and there are many threads (worker threads) that are responsible for processing the received requests. Once a request is processed I need to send an answer over TCP. And here is a question. I would like to send TCP data in ...

Restore context of a thread and continue its execution?

How can I get an idle thread to be activated again such that its context is restored and execution continued (like if I want a thread to activate after 10 seconds and then be activated after every 5 seconds, in the mean time other threads may continue running)? ...

Limit Threads count

Hello, I have a List with items that I want to download. I use a for Loop to iterate the list. For each item in this List I start a new Thread that references the item. My Problem is that I want limit the maxDownload at the same time. for (int i = downloadList.Count - 1; i >= 0; i--) { downloadItem item = downloadList[i]; if (...

Run method from extends Activity extends Runnable

I'm trying to call a method from inside a Runnable that is running. It waits for a string to be entered and when it is then depending on the string (the strings act as commands) it calls a method and is supposed to run whats inside it. public class App extends Activity implements Runnable { public void run() { try { Ser...

onPostExecute on cancelled AsyncTask

Does onPostExecute execute if the AsyncTask has been cancelled? If it does execute, is it safe to say that I should always ask if the task has been cancelled (isCancelled) at the start of onPostExecute, before doing anything else? ...

Concurrent periodic task running

I'm trying to find the best solution for periodic task running in parallel. Requirements: Java (Spring w/o Hibernate). Tasks are being managed by front-end application and stored in MySQL DB (fields: id, frequency (in seconds), <other attributes/settings about task scenario>). -- Something like crontab, only with frequency (seconds) fi...

Using progress bar ends up in not populating list view

I am using a progress bar in android, so that till my data is loaded, user is getting a proper feedback of what is going on. the code for the bar is below: final ProgressDialog myProgressDialog; myProgressDialog = ProgressDialog.show(ListingPage.this,"Please Wait", "Loading Date", true); new Thread() { public void run() { try{...

How to avoid HeadlessException in thread?

I have tried to open a dialog box in Servlet & it opens fine. But then I tried to achieve same thing in my thread's run method. It gaved me following error: java.awt.HeadlessException at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159) at java.awt.Window.<init>(Window.java:431) at java.awt.Frame.<init>(Frame.java...

How do I check that my multithreaded code is actually running on multiple threads?

My program has a list of 200k files. I have to import each to the database. I takes a long time so I started researching about multithreads as a means to speed up the importing process. I finally got to an implementation but I'm not sure it's actually working. After using http://stackoverflow.com/questions/2702545/workaround-for-the-wai...

Why is raising an NSException not bringing down my application?

The Problem I'm writing a Cocoa application and I want to raise exceptions that will crash the application noisily. I have the following lines in my application delegate: [NSException raise:NSInternalInconsistencyException format:@"This should crash the application."]; abort(); The problem is, they don't bring down the application -...

Continuing code execution after a pygtk.main() in python

I have an application where my DataFetch() class "Wraps" around my HBHTray() class for the purpose of interacting with the functions/variables of that class. Unfortunately, I can't seem to be able to get the code to continue execution after my DataFetch() class makes a instance of HBHTray and calls it, and on the Start() method of HBHTra...

Keep thread waiting on windows form response?

I have a windows forms application that runs two threads simultaneously, with the UI thread running in the task bar. The UI thread actually performs completely separate functionality from the other process, but in the case that a new user logs into the application, I need to pop up a setup window from the non-UI thread. Here is the cod...

.Net equivalent of the x86 ASM command XADD

Is there an equivalent of the XADD command in .Net? This is, after all, the most efficient method of locking / checking locks for critical sections or for ensuring accurate increments in a multi-threaded environment. I looked through the IL opcodes, but couldn't find an equivalent. ...

Threading Architecture Question C++ Message Passing

Simple question, I think. I have one thread that responds to a callback that is called when a user connects via TCP. That callback wants an answer if I accept or reject the login. Problem is I have to send a login request to a security server via asynchronous message passing and wait for a response. What is the best way to handle t...

Atomically incrementing counters stored in ConcurrentHashMap

I would like to collect some metrics from various places in a web app. To keep it simple, all these will be counters and therefore the only modifier operation is to increment them by 1. The increments will be concurrent and often. The reads (dumping the stats) is a rare operation. I was thinking to use a ConcurrentHashMap. The issue i...

update wpf datagrid cell from other thread

I'm trying to implement a simple spreadsheet using WPF datagrid. When users input a formula in a cell, engine calculates the formula and update the cell with the calculated value. But most of calculations i handle take long time, so i want to calculate those in other threads. I tried to implement this using CellEditEnding event like bel...

Multiple File upload through threads within JSP

I am uploading multiple files within jsp through a thread. But not getting confirmation message when data upload is completed. I have used join() for thread, & then displayed the dialog box after that & its work fine but only single file is uploaded at a time & others are waiting. I have to show dialog box whenever the uploading gets c...

Should I use Threads to accelerate the application

Hi there, I've got an game app displaying a lot of images that need to be processed before being displayed. The set of images need to be refreshed with new ones every 2 seconds. to speed up the display : While the first set of images is displayed, I'd like to prepare in background the next set. I've got a specific class "board" that I...