is there a way to trigger the threadlocal remove method within DropWizard

224 views
Skip to first unread message

Lester Lobo

unread,
Oct 6, 2014, 2:59:13 PM10/6/14
to dropwiz...@googlegroups.com
I built a webservice in DropWizard that accesses a third party library that is not thread safe. The vendor requested creating a new instance per request.

In order to avoid the overhead of creating a new instance each time, I implemented the a Thread-local wrapper for the third party class.

The application runs fine now multithreaded concurrent requests however crashes on a Full GC. I suspect an issue with the ThreadLocal Object deallocation.

Any ideas ?

Shan Syed

unread,
Oct 6, 2014, 3:37:20 PM10/6/14
to dropwiz...@googlegroups.com
just curious, so are all the requests lining up to use the same instance? I'm just fuzzy on how 

in lieu of this, perhaps consider (if you haven't) creating a bunch of them upon initialization, and make them available to your requests via an object pool





--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lance N.

unread,
Oct 6, 2014, 7:58:42 PM10/6/14
to dropwiz...@googlegroups.com
The Threadlocal variables need to get freed somehow. It sounds like you have a thread pool which is never shrunk. Many threads end up with ThreadLocal variables that are never freed.

When your thread code exits it needs to release the variable. This might be ThreadLocal.set(null) ?

What is the overhead of creating a new instance? Have you micro-benchmarked it? You may find this optimization is not necessary.
Reply all
Reply to author
Forward
0 new messages