aspose file tools*
The moose likes Threads and Synchronization and the fly likes Last task not executed by thread from thread pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Last task not executed by thread from thread pool" Watch "Last task not executed by thread from thread pool" New topic
Author

Last task not executed by thread from thread pool

suvelee sarpotdar
Greenhorn

Joined: Apr 20, 2009
Posts: 4
Hi All,

I am not sure if this problem has been addressed in any of the previous posts. I have implemented a thread pool manager which creates 5 threads and assigns task to these threads. The thread pool manager waits for all threads to finish and also for all tasks to finish before exiting. The task given to the threads consists of connecting to Oracle database and executing a SQL proc to update records in a table.

If I execute the jar file for this application on a windows based machine, I get the results as expected. However if I run the same jar file on linux platform, the last task is not executed by any of the threads. The behavior of the application is random on linux machine. Sometimes it gives results as expected sometimes it doesn't. Both windows and linux machines have the same JRE installed (1.5).

I am not sure how to debug this issue. Any kind of pointers are most welcomed. Thanks in advance.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

suvelee sarpotdar wrote:I have implemented a thread pool manager which creates 5 threads and assigns task to these threads.


You mean you have created your own thread pool? OR you are using the thread pool that comes with JDK?

If you have implemented your own, then without seeing the code, it will be very hard to tell anything.

In any case, I will be surprised if its an OS problem.

How, do you determine that the last task is not executed by the pool? Do you dump any statistics?
Is it so that your task is throwing some kind of Error and the thread is getting killed?


apigee, a better way to API!
suvelee sarpotdar
Greenhorn

Joined: Apr 20, 2009
Posts: 4
Thanks for the reply. I implemented thread pool from scratch. I have given some system.out statements which are printed from the task. No statements are printed from the last task. Also at the end of the program, I am expecting 40,000 records in my table. However only 35,000 records are written into the table since the last task is not executed.

Code snippet from thread pool that assigns task and creates thread if no idle threads are found or waits for one of the threads to finish


Code snippet that waits for all tasks to finish executing


Code snippet from the worker thread which executes the runnable task.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Last task not executed by thread from thread pool