4242//import sun.reflect.CallerSensitive;
4343//import sun.reflect.Reflection;
4444//import sun.security.util.SecurityConstants;
45-
45+ import swingjs . JSThreadGroup ;
4646import swingjs .JSToolkit ;
4747import swingjs .JSUtil ;
4848
@@ -207,7 +207,8 @@ private static synchronized int nextThreadNum() {
207207
208208 /* For generating thread ID */
209209 private static long threadSeqNumber ;
210- public static Thread thisThread ;
210+
211+ public static JSThread 秘thisThread ;
211212
212213 /* Java thread status for tools,
213214 * initialized to indicate thread 'not yet started'
@@ -275,51 +276,34 @@ private static synchronized long nextThreadID() {
275276 * @return the currently executing thread.
276277 */
277278 public static Thread currentThread () {
278- /**
279- * @j2sNative
280- *if (java.lang.Thread.thisThread === "working")
281- * return null;
282- *
283- *
284- */
285- {}
286- if (thisThread == null ) {
287- /**
288- *
289- * technically, JSThread is an abstract class, but we go ahead and
290- * instantialize it anyway in JavaScript. The reason it is abstract
291- * is to force generation of necessary methods when using it.
292- *
293- * @j2sNative
294- *
295- *
296- * java.lang.Thread.thisThread = "working";
297- * java.lang.Thread.thisThread =
298- * Clazz.new_(java.lang.Thread.c$$S, ["master"]);
299- * var name = J2S._applets["master"]._id; var g =
300- * Clazz.new_(Clazz.load('swingjs.JSThreadGroup').c$$ThreadGroup$S,
301- * [null, name]); java.lang.Thread.thisThread =
302- * Clazz.new_(Clazz.load("javajs.util.JSThread").c$$ThreadGroup$S,
303- * [g, name]);
304- *
305- */
306- {
307- // these are for reference only -- not used in JavaScript
308- JSThread .interrupted ();
309- new swingjs .JSThreadGroup (null , null );
310- thisThread = new Thread ("master" );
311- }
312- thisThread .setPriority (NORM_PRIORITY );
279+ Thread t = 秘thisThread ;
280+ if ((Object ) t == "working" )
281+ return null ;
282+ if (t == null ) {
283+ 秘thisThread = (JSThread ) (Object ) "working" ;
284+ 秘thisThread = (JSThread ) new Thread ("master" );
285+ String name = /** @j2sNative J2S._applets["master"]._id || */ null ;
286+ @ SuppressWarnings ("unused" )
287+ JSThreadGroup g = new JSThreadGroup (null , name );
288+ 秘thisThread = /** @j2sNative
289+ Clazz.new_(Clazz.load("javajs.util.JSThread").c$$ThreadGroup$S,
290+ [g, name]) || */ null ;
291+
292+ // new JSThread(g, name);
293+ // technically, JSThread is an abstract class, but we go ahead and
294+ // instantialize it anyway in JavaScript. The reason it is abstract
295+ // is to force generation of necessary methods when using it.
296+ 秘thisThread .setPriority (NORM_PRIORITY );
313297 }
314- return thisThread ;
298+ return 秘thisThread ;
315299 }
316300
317301 /**
318302 * Causes the currently executing thread object to temporarily pause
319303 * and allow other threads to execute.
320304 */
321305 public static void yield () {
322- // SwingJS ;
306+ JSUtil . notImplemented ( null ) ;
323307 }
324308
325309 /**
@@ -335,7 +319,8 @@ public static void yield() {
335319 * @see Object#notify()
336320 */
337321 public static void sleep (long millis ) throws InterruptedException {
338- // SwingJS ;
322+ JSUtil .notImplemented (null );
323+ JSUtil .warn ("SwingJS does not implement Thread.sleep(long)" );
339324 }
340325 /**
341326 * Causes the currently executing thread to sleep (cease execution)
@@ -368,8 +353,9 @@ public static void sleep(long millis, int nanos)
368353 if (nanos >= 500000 || (nanos != 0 && millis == 0 )) {
369354 millis ++;
370355 }
371-
372- sleep (millis );
356+ JSUtil .notImplemented (null );
357+ JSUtil .warn ("SwingJS does not implement Thread.sleep(long,int)" );
358+ // sleep(millis);
373359 }
374360
375361 /**
@@ -394,7 +380,7 @@ private void init(ThreadGroup g, Runnable target, String name,
394380 */
395381 private void init (ThreadGroup g , Runnable target , String name ,
396382 long stackSize , Object acc ) { // was access controller
397- Thread parent = (thisThread == null ? null : thisThread );
383+ Thread parent = (秘thisThread == null ? null : 秘thisThread );
398384// SecurityManager security = System.getSecurityManager();
399385 if (g == null ) {
400386 /* Determine if it's an applet or not */
@@ -418,13 +404,13 @@ private void init(ThreadGroup g, Runnable target, String name,
418404 g = newThreadGroup (null , name );
419405 parent = this ; // ??
420406 }
421- /* checkAccess regardless of whether or not threadgroup is
422- explicitly passed in. */
423- g .checkAccess ();
424-
425- /*
426- * Do we have the required permissions?
427- */
407+ // /* checkAccess regardless of whether or not threadgroup is
408+ // explicitly passed in. */
409+ // g.checkAccess();
410+ //
411+ // /*
412+ // * Do we have the required permissions?
413+ // */
428414// if (security != null) {
429415// if (isCCLOverridden(getClass())) {
430416// security.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
@@ -744,8 +730,9 @@ public synchronized void start() {
744730 }
745731
746732 private void start0 (){
747- started = true ;
748- JSToolkit .dispatch (this , 0 , 0 ); // run the run() method asynchronously
733+ started = true ;
734+ currentThread ().getThreadGroup ().秘transferJ2SInfo (getThreadGroup ());
735+ JSToolkit .startThread (this ); // run the run() method asynchronously
749736 }
750737
751738 /**
@@ -1293,28 +1280,27 @@ public int countStackFrames(){
12931280 */
12941281 public final synchronized void join (long millis )
12951282 throws InterruptedException {
1296- long base = System .currentTimeMillis ();
1297- long now = 0 ;
1283+ // long base = System.currentTimeMillis();
1284+ // long now = 0;
12981285
12991286 if (millis < 0 ) {
13001287 throw new IllegalArgumentException ("timeout value is negative" );
13011288 }
1302-
1303- JSUtil .warn ("Cannot wait in Thread" );
1304- if (millis == 0 ) {
1305- while (isAlive ()) {
1306- wait (0 );
1307- }
1308- } else {
1309- while (isAlive ()) {
1310- long delay = millis - now ;
1311- if (delay <= 0 ) {
1312- break ;
1313- }
1314- wait (delay );
1315- now = System .currentTimeMillis () - base ;
1316- }
1317- }
1289+ JSUtil .notImplemented (null );
1290+ // if (millis == 0) {
1291+ // while (isAlive()) {
1292+ // wait(0);
1293+ // }
1294+ // } else {
1295+ // while (isAlive()) {
1296+ // long delay = millis - now;
1297+ // if (delay <= 0) {
1298+ // break;
1299+ // }
1300+ // wait(delay);
1301+ // now = System.currentTimeMillis() - base;
1302+ // }
1303+ // }
13181304 }
13191305
13201306 /**
0 commit comments