java - How to get ExecutorService or CompletionService to finish without asking for values of Futures? -


we have work done within thread run on server web app using spring boot .

what want happen is: 1) work submitted our custom runnable object 2) work completes when gets turn (it's database operation, , don't need return value except perhaps returning "success" if run() completed without exceptions)

however, in our junit tests, seems tasks submitted executorservice or completionservice disappear when main thread finished, unless call take() every time add new task (since blocks until task finished, makes tasks run sequentially, defeats purpose) or if maintain list of futures , call method loop through list , get() value of each feature.

the latter option don't think ideal because server application, have requests coming in different users , don't know how detect when should clearing out list of futures.

why threads silently disappear , way around this?

don't run code async: test runnable directly:

@test public void test() {     runnable r = <your runnable>;     r.run();     // various assertions } 

it's pointless testing chosen executorservice job - can assume that.

if want assert application behaving correctly, use functional tests; ie, spin container (eg using @springjunit4classrunner) hypersonic datasource, hit spring boot end point make assertions effect on database.

if use spring boot's @async annotation service, can provide configuration uses synchronoustaskexecutor don't have pause in test before making assertions.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -