redragon7964
Programmer
user inputs several time points, after program starts, it will create a new thread when reach a time point, every thread should append current running time with its output, result looks like this:
java barbershop -c 1000 1500 2500 4000
current time 0: barber is sleeping....
current time 1000: customer 1 enter.
current time 1000: barber starts cutting the hair of customer 1
current time 1500: customer 2 enter.
current time 2000: barber stopped cutting the hair of customer 1
current time 2000: barber starts cutting the hair of customer 2
current time 2500: customer 3 enter
.......
at first, i achieve this by record program start time: static final long startTime=System.currentTimeMillis();
and then, every time i need new time, i write: int currentTime=(int)(System.currentTimeMillis()-startTime).
the problem is, when two users come too closely, program still performs the first user's routine but the second user arrival time has been pasted, therefore, second one will be ignored by the program, how to deal with that.
some one suggests me use Timer, but i have no idea how to use it, can someone give me some hints, thanks
java barbershop -c 1000 1500 2500 4000
current time 0: barber is sleeping....
current time 1000: customer 1 enter.
current time 1000: barber starts cutting the hair of customer 1
current time 1500: customer 2 enter.
current time 2000: barber stopped cutting the hair of customer 1
current time 2000: barber starts cutting the hair of customer 2
current time 2500: customer 3 enter
.......
at first, i achieve this by record program start time: static final long startTime=System.currentTimeMillis();
and then, every time i need new time, i write: int currentTime=(int)(System.currentTimeMillis()-startTime).
the problem is, when two users come too closely, program still performs the first user's routine but the second user arrival time has been pasted, therefore, second one will be ignored by the program, how to deal with that.
some one suggests me use Timer, but i have no idea how to use it, can someone give me some hints, thanks