litesoft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
package org.litesoft.delayed.nonpublic;
import java.util.*;
import org.litesoft.core.delayed.nonpublic.*;
import org.litesoft.core.util.*;
public class ThreadBasedDelayedTimedRunnableRunner extends AbstractDelayedTimedRunnableRunner
{
private final MyRunnable mMyRunnable;
public ThreadBasedDelayedTimedRunnableRunner()
{
super( LoggingUnexpectedExceptionHandler.INSTANCE );
mMyRunnable = new MyRunnable();
}
protected void LLscheduleFor( long pWhenTimeInMilliSecs, long pNowInMilliSecs )
{
if ( pWhenTimeInMilliSecs <= 0 )
{
throw new IllegalArgumentException( "WhenTimeInMilliSecs is not greater than 0 with (" + //
mTimedRunnable.getClass() + "): " + pWhenTimeInMilliSecs );
}
mMyRunnable.scheduleFor( pWhenTimeInMilliSecs );
}
protected void LLcancel()
{
mMyRunnable.cancel();
}
public boolean isScheduled()
{
return mMyRunnable.isScheduled();
}
private class MyRunnable implements Runnable
{
private Thread mMyThread = null;
private Long mTillTime = null;
public synchronized boolean isScheduled()
{
return (mTillTime != null);
}
public synchronized void scheduleFor( long pWhenTimeInMilliSecs )
{
mTillTime = pWhenTimeInMilliSecs;
if ( mMyThread != null )
{
notifyAll();
}
else
{
mMyThread = new Thread( this );
mMyThread.setDaemon( true );
mMyThread.start();
}
}
public void run()
{
while ( waitTillTime() )
{
LLrun();
}
}
private synchronized boolean waitTillTime()
{
while ( mMyThread != null )
{
try
{
while ( mTillTime == null )
{
wait();
}
long zNow = new Date().getTime();
if ( mTillTime <= zNow )
{
mTillTime = null;
return true;
}
long milliSecsToWait = mTillTime - zNow;
wait( milliSecsToWait );
}
catch ( InterruptedException e )
{
// Whatever...
}
}
return false;
}
public synchronized void cancel()
{
mTillTime = null;
if ( mMyThread != null )
{
notifyAll();
}
}
}
}
|
Revision |
Author |
Commited |
Message |
2
|
GeorgeS
|
Sun 07 Feb, 2010 12:50:58 +0000 |
|