How to add timestamp into a multi threaded program where I have:
- J3 dependent on J1 & J2
- J5 dependent on J4
And get the different times of executions of each job (thread).
I have 6 different files of J1, J2, J3 (where I have joined J1 & J2), J4, J5 (where I have joined J4) and J6 (where I start all the threads).
I have added this function:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:ms");
Calendar cal = Calendar.getInstance();
Sample Code(of one thread) --
import java.io.*;
import java.*;
import java.util.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Job1 extends Thread{
String msg;
public void run()
{
System.out.println("Execution of job1 (addition job) started");
System.out.println();
System.out.print("3+2=" +(3+2));
System.out.println();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:ms");
Calendar cal = Calendar.getInstance();
}
Job1(String mg)
{
msg=mg;
}
}
But, I am getting the same time for every thread.
Update
This is the output I am getting.
C:\Program Files\Java\jdk1.6.0_03\bin>javac threadcontainer.java
C:\Program Files\Java\jdk1.6.0_03\bin>java threadcontainer
J1->4719906194666
J2->4719906696464
Execution of job1 (addition job) started
3+2=5
J4->4719911159535
Execution of job4 (multiplication job) started
3*2=6Job 5 executing
J5-> 4719911737462
Execution of job2 (subtraction job) started
3-2=1Job 3 executing
J3->4719912405874