@@ -89,15 +89,11 @@ public static SwtExec immediate() {
89
89
immediate = new SwtExec (Display .getDefault ()) {
90
90
@ Override
91
91
public void execute (Runnable runnable ) {
92
- requireNonNull (runnable );
93
- if (!display .isDisposed ()) {
94
- if (Thread .currentThread () == display .getThread ()) {
95
- runnable .run ();
96
- } else {
97
- display .asyncExec (runnable );
98
- }
92
+ if (Thread .currentThread () == swtThread ) {
93
+ runnable .run ();
99
94
} else {
100
- throw new RejectedExecutionException ();
95
+ requireNonNull (runnable );
96
+ display .asyncExec (runnable );
101
97
}
102
98
}
103
99
};
@@ -146,15 +142,11 @@ private Blocking() {
146
142
147
143
@ Override
148
144
public void execute (Runnable runnable ) {
149
- requireNonNull (runnable );
150
- if (!display .isDisposed ()) {
151
- if (Thread .currentThread () == display .getThread ()) {
152
- runnable .run ();
153
- } else {
154
- display .syncExec (runnable );
155
- }
145
+ if (Thread .currentThread () == swtThread ) {
146
+ runnable .run ();
156
147
} else {
157
- throw new RejectedExecutionException ();
148
+ requireNonNull (runnable );
149
+ display .syncExec (runnable );
158
150
}
159
151
}
160
152
@@ -165,7 +157,7 @@ public void execute(Runnable runnable) {
165
157
* @return the value which was returned by supplier.
166
158
*/
167
159
public <T > T get (Supplier <T > supplier ) {
168
- if (Thread .currentThread () == display . getThread () ) {
160
+ if (Thread .currentThread () == swtThread ) {
169
161
return supplier .get ();
170
162
} else {
171
163
Nullable <T > holder = Nullable .ofVolatileNull ();
@@ -317,6 +309,7 @@ private Subscription subscribe(Supplier<Subscription> subscriber) {
317
309
}
318
310
319
311
protected final Display display ;
312
+ protected final Thread swtThread ;
320
313
protected final Rx .RxExecutor rxExecutor ;
321
314
322
315
/** Returns an instance of {@link com.diffplug.common.rx.Rx.RxExecutor}. */
@@ -327,11 +320,13 @@ public Rx.RxExecutor getRxExecutor() {
327
320
328
321
SwtExec (Display display ) {
329
322
this .display = display ;
323
+ this .swtThread = display .getThread ();
330
324
this .rxExecutor = Rx .on (this , new SwtScheduler (this ));
331
325
}
332
326
333
327
SwtExec (Display display , Rx .RxExecutor rxExecutor ) {
334
328
this .display = display ;
329
+ this .swtThread = display .getThread ();
335
330
this .rxExecutor = rxExecutor ;
336
331
}
337
332
@@ -354,11 +349,7 @@ public Rx.RxExecutor getRxExecutor() {
354
349
@ Override
355
350
public void execute (Runnable runnable ) {
356
351
requireNonNull (runnable );
357
- if (!display .isDisposed ()) {
358
- display .asyncExec (runnable );
359
- } else {
360
- throw new RejectedExecutionException ();
361
- }
352
+ display .asyncExec (runnable );
362
353
}
363
354
364
355
////////////////////////////////////////////////////////
0 commit comments