Created
July 29, 2015 08:55
-
-
Save eungjun-yi/ddb2eef3da25697a06b3 to your computer and use it in GitHub Desktop.
마크다운 렌더러에서 어쩔 수 없이 Thread.stop() 사용함
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
// 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