Vote count:
0
I have thread which download data from HTTP. I get it every 1 seconds to about 10 minutes using stream API.
After I receive data from HTTP server I need send this data to method in MyMainClass
. How can I do that without static method? I don't like to use static method.
public class MyMainClass {
public static void main(String[] args) {
GetData getData = new GetData();
getData.start();
}
public static void useText(String text) {
System.out.println(text);
// do something...
}
}
public class GetData extends Thread {
@Override
public void run() {
String text;
/* Download text from HTTP and save it to "text".
* Every 1 seconds to about 10 minutes using stream API.
* text= "abc...";
* If there are no errors, run method never exit.
*/
MyMainClass.useText(text);
}
}
asked 22 secs ago
Java: periodically sending data from thread to main class
Aucun commentaire:
Enregistrer un commentaire