Skip to content

Instantly share code, notes, and snippets.

@gtrak
Created September 7, 2011 03:40
Show Gist options
  • Save gtrak/1199708 to your computer and use it in GitHub Desktop.
Save gtrak/1199708 to your computer and use it in GitHub Desktop.
callback demo
package com.garytrakhman;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class ThreadTest {
List<String> strings = new ArrayList<String>();
public synchronized void post(String s) {
strings.add(s);
}
public static void main() {
final ThreadTest test = new ThreadTest();
Thread a = new Thread(new Runnable() {
@Override
public void run() {
BufferedReader pipe;
Process process;
pipe = new BufferedReader(new InputStreamReader(
process.getInputStream()));
try {
while (true) {
test.post(pipe.readLine());
Thread.sleep(200);
}
} catch (InterruptedException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment