java - Execute thread periodically until Future value matches criteria -


i need stall main thread until particular situation happens, can start different thread.

to freeze main thread thought of launching thread checked particular situation periodically. when situation reached, can launch second thread.

i knew "return value" of thread using future , callable in fashion , knew how schedule threads.

but how can mix both?

this trying do:

thread startresolution = new thread(() -> target(path + "/" + id + "/schedule").request().get()); thread stopresolution = new thread(() -> {     response response = target(path + "/" + id + "/schedule/stop-resolution").request().get();     system.out.println(response.readentity(string.class)); });  startresolution.start();  // want lock main thread here until returs particular state target(path + "/" + id + "/schedule/resolution-state").request().get(string.class);  stopresolution.start(); startresolution.join(); stopresolution.join(); 

how using tools mentioned? or maybe cyclicbarrier better fit scenario?

the fact http requests mixed in situation makes hard me figure out approach.

create , start thread checks on required state , exits when state happens, join() it. main thread block on join until state occurs.

alternatively, put code checking required state @ beginning of stopresolution thread , start right away; thread wait required state before proceeding logic in it. in case main thread doesn't have change @ all.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -