Skip to content

Instantly share code, notes, and snippets.

@eungjun-yi
Created July 29, 2015 08:55
Show Gist options
  • Save eungjun-yi/ddb2eef3da25697a06b3 to your computer and use it in GitHub Desktop.
Save eungjun-yi/ddb2eef3da25697a06b3 to your computer and use it in GitHub Desktop.
마크다운 렌더러에서 어쩔 수 없이 Thread.stop() 사용함
// Try to render and wait at most 5 seconds.
final String[] rendered = new String[1];
@SuppressWarnings("deprecation")
Thread marked = new Thread() {
@Override
public void run() {
try {
rendered[0] = (String) ((Invocable) engine).invokeFunction(
"marked", source, options);
} catch (Exception e) {
play.Logger.error("[Markdown] Failed to render: " + source, e);
}
}
};
marked.start();
marked.join(5000);
if (rendered[0] == null) {
// This is the only way to stop the script engine. Thread.interrupt does not work.
marked.stop();
return "〈pre〉" + StringEscapeUtils.escapeHtml(source) + "〈/pre〉";
} else {
return rendered[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment