java - @Async with outstream and thread.sleep method -


a simple question on @async annotation.

for example: method @async annotated , contains thread.sleep few seconds. , after sleep, outstream.println. result.

i have used threadpooltaskexecutor executor

i want know have tried above sleep of 5 seconds, getting outstream.println in fraction of second. want understand if how async annotation works i.e., if has given instant response , thread.sleep executed other thread.

assuming method this

@async public void foo() {     sleep(5000l);     system.out.println("hello world"); } 

this won't tell 5sec wait in thread anyway. if have this

public void bar() {     myservice.foo();     system.out.println("hello world"); } 

then if hello world in "a fraction of second", means invocation of foo has been indeed done asynchronously.

when invoke method @async method invocation wrapped in callable , instance passed executor service using submit method.

if executor cannot process method execution, you'll taskrejectedexception. instance, if threadpooltaskexecutor has pool size of 2 threads , queue size of 0, third invocation of foo method fail taskrejectedexception if pool threads still busy processing 2 first invocations.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -