Created
February 9, 2014 22:38
-
-
Save mvberg/8907119 to your computer and use it in GitHub Desktop.
How to prevent ActiveTick's Java API from dead locking on shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this call will dead lock if feed has been logged in from another | |
// location | |
// apiSession.getSession().DestroySession(); | |
// AND apiSession.getSession().IsConnected() will still == true ?!?! | |
log.warn("AT Feed, session connected = " + apiSession.getSession().IsConnected()); | |
Field dClassField = at.feedapi.Session.class.getDeclaredField("A"); | |
dClassField.setAccessible(true); | |
Field bClassField = at.feedapi.Session.class.getDeclaredField("I"); | |
bClassField.setAccessible(true); | |
final Object dClassInstance = dClassField.get(apiSession.getSession()); | |
final Object bClassInstance = bClassField.get(apiSession.getSession()); | |
log.debug("D ClassInstance = " + dClassInstance); | |
log.debug("B ClassInstance = " + bClassInstance); | |
// No idea what this stands for since code is obuscated | |
// but setting it to false and interrupting threads in "D class" | |
// does the trick | |
Field cBooleanInBClass = at.feedapi.B.class.getDeclaredField("C"); | |
cBooleanInBClass.setAccessible(true); | |
cBooleanInBClass.set(bClassInstance, false); | |
Field fBooleanInDClass = at.feedapi.D.class.getDeclaredField("F"); | |
fBooleanInDClass.setAccessible(true); | |
// | |
Field pThreadField = at.feedapi.D.class.getDeclaredField("P"); | |
pThreadField.setAccessible(true); | |
Field bThreadField = at.feedapi.D.class.getDeclaredField("B"); | |
bThreadField.setAccessible(true); | |
final Thread bThread = (Thread) pThreadField.get(dClassInstance); | |
final Thread pThread = (Thread) bThreadField.get(dClassInstance); | |
bThread.interrupt(); | |
pThread.interrupt(); | |
// | |
fBooleanInDClass.set(dClassInstance, false); | |
// my god, these threads should just be daemon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. This has probably saved me lots of grief. :)