Multithreading

I am trying to speed up my java web application by using multiple threads. I need to execute 4 tasks that send XML requests with HTTP POST method, parse the XML response and initialize related JSF managed beans. Additionally, the application is required to send SIP messages every 2 minutes to server.

I decided i need a ScheduledThreadPoolExecutor. Here's a snippet of the code I plan to write this morning at work:


ScheduledExecutorService pool
= Executors.newScheduledThreadPool(5);

pool.execute(new Runnable() {
public void run() {
// First task
}
});
pool.execute(new Runnable() {
public void run() {
// Second task
}
});
pool.execute(new Runnable() {
public void run() {
// Third task
}
});
pool.execute(new Runnable() {
public void run() {
// Fourth task
}
});

Runnable sendSIPMessages = new Runnable(){
public void run() {
// Send SIP messages
}
};

pool.scheduleAtFixedRate(sendSIPMessages, 0, 2, TimeUnit.MINUTES);
pool.shutdown();

I'll try it tomorrow. The thing that worries me is that I need a way to be assured that the first 4 tasks have been completed before going on with the rest of the code (I think awaitTermination method is what I need). Any hints?

Update: I gave up trying to code using threads. Something went wrong with ScheduledExecutorService pool. The periodic task seemed to either run for ever or didn't run at all. I am sure i wrote something wrong at the code but after 2 days of trying I decided to work with Quartz to send periodically SIP messages. Alas, i faced new problems....

I used Spring with Quartz to initiate a job that sends SIP messages every 90 seconds. When the user logs out the job should be stopped, deleted, unscheduled (call it whatever you want). I don't understand how to do it with Spring, so i made it work without using Spring (but I should because it's so elegant!).
1