Skip to content

Instantly share code, notes, and snippets.

@mvberg
Created February 9, 2014 22:38
Show Gist options
  • Save mvberg/8907119 to your computer and use it in GitHub Desktop.
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 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
@gregbarton
Copy link

Thanks. This has probably saved me lots of grief. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment