Created
September 7, 2011 03:40
-
-
Save gtrak/1199708 to your computer and use it in GitHub Desktop.
callback demo
This file contains 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
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