java - Misusing ThreadPoolExecutor - OOM errors -
im reading files sqs in unbounded stream. read each file want submit second queue processing. can simultaneously process several files put these threads , want block further reads queue when threads in use.
to end used this:
executorservice executorservice = new threadpoolexecutor( maxthreads, // core thread pool size maxthreads, // maximum thread pool size 1, // time wait before resizing pool timeunit.minutes, new arrayblockingqueue<runnable>(maxthreads, true), new threadpoolexecutor.callerrunspolicy());
where maxthreads = 2
.
files read in blocks of ten , processed such:
for (message msg : resp.getmessages()) { gson g = new gson(); messagebody messagebody = g.fromjson(msg.getbody(), messagebody.class); messagerecords messagerecords = g.fromjson(messagebody.getmessage(), messagerecords.class); list<messagerecords.record> records = messagerecords.getrecords(); executorservice.submit(new runnable() { @override public void run() { ... work based on file type } });
watching thread count im seeing climb steadily until system runs out of memory, closes job unable create native thread exception. after vm(aws) doesn't accept ssh logins until gets stopped / restarted.
it seems there must step given thread released / cleaned im not seeing should happen.
what doing wrong?
edit:
- yes,
run()
finish , exit - nothing else interacts these threads.
run()
method gets file, looks @ type , calls fn() based on type. function parses file , returns.run()
finished.
the issue use of threadpoolexecutor
. appear(s/ed) in app process. creating new thread pool each loop through block of sqs messages , not closing afterwards. moving creation outside loop , reusing same block fixes problem.
so - big hairy ufu.
Comments
Post a Comment