java - Pass a function to PoolThread -



java - Pass a function to PoolThread -

i've classes generate lot of threads , application , takes lot of memory. have decided utilize poolthread decrease threads overhead. poolthread managed in class , have question: how can pass generic function parameter , execute 1 time in poolthread? e.g.

public void executefunction( myfunction) { executorservice.execute(new runnable() { public void run() { run function i've passed } } }

as functions have no proper existence in java, improve give executorservice runnable (or improve callable) object containing code execute, method returning corresponding future.

in fact, believe or not, method exists in executorservice : <t> future<t> submit(callable<t> task)

the future#get() method allow wait until result obtained.

java multithreading reflection

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -