File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Last task not executed by thread from thread pool

 
suvelee sarpotdar
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
suvelee sarpotdar
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic