# Detach java agent runtime

**URL:** <https://discuss.elastic.co/t/detach-java-agent-runtime/191870>\
**Category:** APM\
**Tags:** java\
**Created:** [July 23, 2019, 4:41pm UTC](https://discuss.elastic.co/t/detach-java-agent-runtime/191870 "2019-07-23T16:41:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gajanan8086](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gajanan8086/32/50604_2.png) [@gajanan8086](https://discuss.elastic.co/u/gajanan8086)\
**Post date:** [July 23, 2019, 4:41pm UTC](https://discuss.elastic.co/t/detach-java-agent-runtime/191870/1 "2019-07-23T16:41:03Z")

</div>

Hi Team,  
I believe provision for detaching java agent from the process without restarting is quite critical. This will be one of the key feature asked during go live. I see that changing the value for "elastic.apm.active" to false dynamically can stop the instrumentation, however the object pools and other threads will remain in the JVM.

One of the option could to call "ElasticApmInstrumentation.tracer.stop()" from JMX or somewhere. Though this stops most of the APM related threads and unloads the instrumentation I still see apm-reporter thread running.

Would this be the right approach to detach the agent?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [July 26, 2019, 10:40am UTC](https://discuss.elastic.co/t/detach-java-agent-runtime/191870/2 "2019-07-26T10:40:21Z")

</div>

> [@gajanan8086](#):
>
> however the object pools and other threads will remain in the JVM.

What's your concern when these are still running?

Setting `elastic.apm.active` should do what you want and also gives you the possibility to activate the agent again at runtime.

> [@gajanan8086](#):
>
> I still see apm-reporter thread running

After a timeout of 5s this thread should stop too.

---

<div class="post-metadata">

**Author:** ![gajanan8086](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gajanan8086/32/50604_2.png) [@gajanan8086](https://discuss.elastic.co/u/gajanan8086)\
**Post date:** [August 7, 2019, 11:39am UTC](https://discuss.elastic.co/t/detach-java-agent-runtime/191870/3 "2019-08-07T11:39:38Z")

</div>

If we just use `elastic.apm.active=false`, no matter how long we wait threads `apm-reporter`, `apm-request-timeout-timer`, `configuration-reloader`, `apm-metrics-reporter` will still be running. The only way to stop these threads is using stop method.

Please refer the [Other Thread](https://discuss.elastic.co/t/java-apm-client-transfer-transaction-information-when-using-blockingqueue-instead-of-executorservice/191781/11) to know why I want all threads to be closed, issue with `active` flag and what are the actions I am taking to dettach the agent.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 28, 2019, 7:39am UTC](https://discuss.elastic.co/t/detach-java-agent-runtime/191870/4 "2019-08-28T07:39:44Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
