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

15
LINES

< > BotCompany Repo | #1009045 // fillVar - fill a global variable in a synchronized way. does it only once

JavaX fragment (include)

static new HashSet<S> fillVar_set;

// make: func -> var type; or a class
// TODO: better synchronisation
// also, might return null while var is filled by another thread
static O fillVar(S var, O make) {
  synchronized(fillVar_set) {
    if (fillVar_set.contains(var)) ret get(mc(), var);
    fillVar_set.add(var);
  }
  O o = make instanceof Class ? nuInstance((Class) make) : callF(make);
  set(mc(), var, o);
  synchronized(fillVar_set) {} // sync?
  ret o;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009045
Snippet name: fillVar - fill a global variable in a synchronized way. does it only once
Eternal ID of this version: #1009045/3
Text MD5: 003c2d502230173d80c692d404fc53a8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-24 17:43:54
Source code size: 477 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 444 / 490
Version history: 2 change(s)
Referenced in: [show references]