Skip to content

Instantly share code, notes, and snippets.

@avshabanov
Created April 28, 2015 04:54
Show Gist options
  • Save avshabanov/2a02fa6762d99b8144b9 to your computer and use it in GitHub Desktop.
Save avshabanov/2a02fa6762d99b8144b9 to your computer and use it in GitHub Desktop.
Simple Repl on Java

Start

java -cp out/production/SimpleRepl/ repl.SimpleRepl

Profiling using JMX

Start app:

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1098 -cp ~/bin/SimpleRepl/ repl.SimpleRepl

Check port:

netstat -nlp | grep 1098

Then connect remotely.

See also http://hackers.lookout.com/2014/06/profiling-remote-jvms/

package repl;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
/**
* @author Alexander Shabanov
*/
public class SimpleRepl {
public static void printHelp() {
System.out.println("Available commands: printTime, help, exit, quit");
}
public static void main(String[] args) throws IOException {
try (final BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {
for (;;) {
System.out.print("> ");
final String line = r.readLine();
System.out.println();
switch (line) {
case "help":
printHelp();
break;
case "printTime":
System.out.println("Time=" + new Date());
break;
case "quit":case "exit":
return;
default:
System.out.println("Unknown command: " + line);
printHelp();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment