Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HeavyWorkRunnable implements Runnable {
- @Override
- public void run() {
- System.out.println("Doing heavy processing - START "+Thread.currentThread().getName());
- try {
- doDBProcessing();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("Doing heavy processing - END "+Thread.currentThread().getName());
- }
- private void doDBProcessing() throws InterruptedException {
- // TODO
- }
- }
- public class ThreadRunExample {
- public static void main(String[] args){
- Thread t1 = new Thread(new HeavyWorkRunnable(), "t1");
- Thread t2 = new Thread(new HeavyWorkRunnable(), "t2");
- System.out.println("Starting Runnable threads");
- t1.start();
- t2.start();
- System.out.println("Doing main heavy processing - START "+Thread.currentThread().getName());
- System.out.println("Runnable Threads has been started");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement