Multithreaded Timer Task

72 views Asked by At

I have a process Scheduled using Timer and TimerTask that runs nightly. Currently ti takes about an hour to finish. Considering there are only 6000 records to loop through the process and the upper management feels like it is very inefficient Job. So I wanted to know if I could span multiple threads of the same job with different datasets. Probaby each thread processes only 500 records at a time.

  1. If i am hitting the same table for read/insert and update using multiple threads would that be ok to do it?
  2. if so how do i run multiple threads within a timer task? I suppose I could just create threads and run but how do i ensure they run simultaneously but not sequentially?

I am using java 1.4 and this runs on a jboss 2.4 and i make use EJB 1.1 session beans in the process to read/update/add data.

1

There are 1 answers

0
T.D. Smith On

There isn't enough info in your post for a surefire answer, but I'll share some thoughts:

  1. It depends. Generally you can do reads in parallel, but not writes. If you're doing much more reading than writing, you're probably ok, but you may find yourself dealing with frustrating race conditions.

  2. It depends. You are never guaranteed to have threads run in parallel. That's up to the cpu/kernel/jvm to decide. You just make threads to tell the machine that it's allowed to execute them in parallel.