Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to account running time

Status
Not open for further replies.

redragon7964

Programmer
Oct 2, 2003
1
NZ
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
 
Is this a synchronization issue? perhaps you need to block out the handling of the acceptance of the 2nd customer, until the first has been handled/accepted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top