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

23
LINES

< > BotCompany Repo | #1031672 // BetterThread

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

Libraryless. Click here for Pure Java version (3870L/22K).

// a variant of thread where you can get the Runnable target later.
// Also notes its existence on the VM bus.
// We should use this exclusively instead of Thread.

sclass BetterThread extends Thread {
  Runnable target;
  
  *(Runnable *target) { _created(); }
  *(Runnable *target, S name) { super(name); _created(); }
  
  void _created() { vmBus_send threadCreated(this); }
  
  run {
    try {
      vmBus_send threadStarted(this);
      if (target != null) target.run();
    } finally {
      vmBus_send threadEnded(this); 
    }
  }
  
  Runnable getTarget() { ret target; }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031672
Snippet name: BetterThread
Eternal ID of this version: #1031672/7
Text MD5: ae3c430e60869b90ce26212cf6fa54f0
Transpilation MD5: c34cdea33517208967920723da9e4cde
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-26 19:47:08
Source code size: 605 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 132 / 338
Version history: 6 change(s)
Referenced in: [show references]