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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -