Results 1 to 4 of 4
Thread: Work with TIME
- 04-16-2011, 02:24 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
- 04-16-2011, 02:28 AM #2
Member
- Join Date
- Apr 2011
- Location
- Canada!
- Posts
- 30
- Rep Power
- 0
Can you modify the said object?
If yes, then during interaction, as the client you can do something like
setLastInteractionTime(System.currentTimeMillis()) ;
to set the last time you interacted with it.
And then when you get the object back do a comparison between
client's current time and getLastInteractionTime() return.
- 04-16-2011, 02:33 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Yes i can, but my goal is to see "automatically" if 10 minutes have passed.
For exemple: for (each 10 minutes passed) {do something}
how can i do that ?
- 04-16-2011, 03:05 AM #4
Member
- Join Date
- Apr 2011
- Location
- Canada!
- Posts
- 30
- Rep Power
- 0
Do you know the Listener design pattern (ever used keyListener??)
Essentially your object needs to be the Source of events, and it will fire those events every 10 min since last interaction. You'll still need to have something like setLastInteractionTime.
So anyway, the object is a source of events, inside the object there will be a thread (or maybe the thread should be some dispatcher-type class).
The thread will be used for polling the object for its time, on some specified time interval. So your design will be something as follows:
1. There is a dispatcher class which implements Runnable and has a thread in it.
2. Objects are sources of tenMinPassedEvent, which say, passed the name of the said object to whatever implement's that object's listener interface.
3. What's happening inside the dispather is something like this (in semi-pseudocode):
Will be accurate to 5ms time, on Thread.sleep(5) call.Java Code:public void run() { Thread current = Thread.currentThread(); while (current == instanceVarThreadOfDispatcher) { try { Thread.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } pollEveryObject(); //get every object's setLastInteractionTime here, and compare it with current time. If 10 min or more passed, the object generates a tenMinPassedEvent, which is propogated to all other objects which implemented it's Listener interface. }
Similar Threads
-
JAVA Programmers Wanted - Full-Time and Part-Time Positions open
By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM -
webstart link some time doesn't work after Java upgrade
By Richard Gillespie in forum Advanced JavaReplies: 0Last Post: 12-21-2010, 04:01 PM -
calculate time diff for particular time period
By baktha.thalapathy in forum New To JavaReplies: 2Last Post: 05-24-2010, 04:10 PM -
Class Time - represents time of day
By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 01:06 AM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks