}
// watch for loaded classes
addClassWatch(vm);
// process events
EventQueue eventQueue = vm.eventQueue();
// resume the vm
Process process = vm.process();
// Copy target's output and error to our output and error.
Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());
errThread.start();
outThread.start();
vm.resume();
boolean connected = true;
while (connected) {
EventSet eventSet = eventQueue.remove();
for (Event event : eventSet) {
if (event instanceof VMDeathEvent
|| event instanceof VMDisconnectEvent) {
// exit
connected = false;