Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1032605 // testThreadCancellation

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4578L/26K).

1  
// this assures that cancelling threads made in the same realm works.
2  
// for cancelling across realms, another test would be needed.
3  
svoid testThreadCancellation(double extraSleep default 0) {
4  
  new Flag flag1;
5  
  new Flag flag2;
6  
  
7  
  Thread t = startThread("testThreadCancellation", r {
8  
    flag1.raise();
9  
    try {
10  
      busySleepSeconds(20.0);
11  
    } finally {
12  
      flag2.raise();
13  
    }
14  
  });
15  
  flag1.waitUntilUp();
16  
  sleepSeconds(extraSleep);
17  
  assertFalse(flag2.isUp());
18  
  long time = nanoTime();
19  
  cancelThread(t);
20  
  assertTrue("Thread cancellation works", flag2.waitUntilUp(2.0));
21  
  time = nanoTime()-time;
22  
  print("Local thread cancellation works. Took " + renderElapsedNanosPleasantly(time));
23  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032605
Snippet name: testThreadCancellation
Eternal ID of this version: #1032605/7
Text MD5: 7cf48e40ffcd415a66ededf49c9ad8ea
Transpilation MD5: ffac00bc17fcddc297302aa1b0ee6b2b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-24 22:09:50
Source code size: 724 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 213
Version history: 6 change(s)
Referenced in: [show references]