java - When implementing Runnable -
i need: 1. there hot threads (they present, number known beforehand) , free threads (interrupts when timeout expires).
i implement. 1. class hotthread implements runnable. 2. class freethread extends hotthread (added timer). 3. class threadpool planner. has methods: addfreethread(), canceltask(int id).
my addfreethread looks this:
public void addfreethread() { freethread ft = new freethread(timeout); thread t = new thread(ft); ft.starttimer(t); }
now start implement canceltask:
public void canceltask(int id) { ... // thread threadtocancel threadpool. threadtocancel.interrupt(); }
than looks great. timer still running in separate thread. timer started in instance of freethread class seem have lost. knew when started free thread. don't know find it.
that implementing of runnable confuses me lot. maybe can extract ft thread? seems impossible. shall keep in threadpool. looks troublesome keeping hashmap thread , id there. wouldn't keeping hashmap keeping ids , fts.
could give me hint?
there's no way know of thread
's runnable
target @ runtime. can either extend thread
instead of implementing runnable
, or can keep map of freethread
s separately.
Comments
Post a Comment