To crate threads, create a new class that extends the Thread class, and instantiate that class. The extending class must override the run() method and call start() method to begin execution of the thread.
Inside run(), you will define the code that constitutes a new thread. It is important to understand that run() can call other methods, use other classes and declare variables just like the main thread. The only difference is the run() establishes the entry point for another, concurrent thread of execution within your program. This will end when run() returns.
public class MyThread extends Thread {
String word;
public MyThread(String rm){
word = rm;
}
public void run(){
try {
for(;;){
System.out.println(word);
Thread.sleep(1000);
}
} catch(InterruptedException e) {
System.out.println("sleep intreupted");
}
}
public static void main(String[] args) {
Thread t1=new MyThread("First Thread");
Thread t2=new MyThread("Second Thread");
t1.start();
t2.start();
}
}
Output screen:
First Thread
Second Thread
First Thread
Second Thread
First Thread
and see this :
http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
and for Spring you can use thread pool :
http://static.springsource.org/spring/docs/2.0.x/reference/scheduling.html