View | Details | Raw Unified | Return to bug 233319
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java (-1 / +48 lines)
Lines 78-83 Link Here
78
 */
78
 */
79
public class JDIThread extends JDIDebugElement implements IJavaThread {
79
public class JDIThread extends JDIDebugElement implements IJavaThread {
80
	
80
	
81
	// Timeout setting for checking initial thread state
82
	// JDIThread will keep asking the ThreadReference for thread state if it is
83
	// suspended until the timeout has expired
84
	private static final long THREAD_STATE_TIMEOUT = 1000;
85
	
86
	// Timestamp when this thread is created
87
	private long fCreationTimestamp = System.currentTimeMillis();
88
	
89
	// flag to indicate if the thread should refresh thread state
90
	private boolean fCheckThreadState = false;
91
	
81
	/**
92
	/**
82
	 * Constant for the name of the default Java stratum 
93
	 * Constant for the name of the default Java stratum 
83
	 */
94
	 */
Lines 299-305 Link Here
299
			// This may be a transient suspend state (for example, a thread is handling a
310
			// This may be a transient suspend state (for example, a thread is handling a
300
			// class prepare event quietly). The class prepare event handler will notify
311
			// class prepare event quietly). The class prepare event handler will notify
301
			// this thread when it resumes
312
			// this thread when it resumes
302
			setRunning(!fThread.isSuspended());
313
			boolean suspended = fThread.isSuspended();
314
			if (suspended) {
315
				// we can be in transient suspend state, set thread state to
316
				// true;
317
				fCheckThreadState = true;
318
			}
319
			
320
			setRunning(!suspended);
303
		} catch (VMDisconnectedException e) {
321
		} catch (VMDisconnectedException e) {
304
			disconnected();
322
			disconnected();
305
			return;
323
			return;
Lines 1107-1114 Link Here
1107
	 * @see ISuspendResume#isSuspended()
1125
	 * @see ISuspendResume#isSuspended()
1108
	 */
1126
	 */
1109
	public boolean isSuspended() {
1127
	public boolean isSuspended() {
1128
		
1129
		if (fCheckThreadState)
1130
		{
1131
			long currentTime = System.currentTimeMillis();		
1132
			if ((currentTime - fCreationTimestamp) > THREAD_STATE_TIMEOUT)
1133
			{
1134
				// check thread state time out, set fCheckThreadState to false
1135
				fCheckThreadState = false;
1136
			}
1137
			
1138
			// Need to refresh one last time after timeout
1139
			// This is to handle the case where no one has asked if this thread
1140
			// is suspended in the first 500 ms.  (e.g. the thread is suspended but hidden in a view.)
1141
			// When the thread becomes visible, the state of the thread needs to be refreshed.
1142
			refreshThreadState();
1143
		}
1144
		
1110
		return !fRunning && !fTerminated;
1145
		return !fRunning && !fTerminated;
1111
	}
1146
	}
1147
	
1148
	// Since this is in an internal package, can this be a 
1149
	// public method?
1150
	private void refreshThreadState() {
1151
		try {
1152
			boolean suspended = fThread.isSuspended();
1153
			setRunning(!suspended);
1154
		} catch (Exception e) {
1155
			// handle all errors silently as we may get into
1156
			// trouble when thread/VM is gone soon after it has been created
1157
		}		
1158
	}
1112
1159
1113
	/**
1160
	/**
1114
	 * @see ISuspendResume#isSuspended()
1161
	 * @see ISuspendResume#isSuspended()

Return to bug 233319