I work in JavaFX. There are some objects in the start method and there is a nested class Run2 ( class Run2 extends Thread ). In it there is a run method responsible for work of a side stream. How to transfer object from start method to run method?

Closed due to the fact that the essence of the question is not clear to the participants of zRrr , Denis , VenZell , user194374, aleksandr barakin Jul 23 '16 at 6:56 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • The code in the studio, please. - Andrey M

1 answer 1

If correctly understood that:
one)

 public class Main extends Aplication { private Object obj; @Override public void start( Stage stage ) { //some code obj = new SomeThing(); Run2 run2 = new Run( obj ); run2.start(); } private class Run2 extends Thread { private final Objetc obj; public Run2( Object obj ) { this.obj = obj; } public void run() { //some code } } } 

2)

 public class Main extends Aplication { private Object obj; @Override public void start( Stage stage ) { //some code obj = new SomeThing(); Run2 run2 = new Run(); run2.setObjetc( obj ); run2.start(); } private class Run2 extends Thread { private Objetc obj; pubic void setObject( Object obj ) { this.obj = obj; } public void run() { if ( obj == null ) throw new IllegalArgumentException( "Объект не инициализирован!" ); //some code } } } 

Not knowing the context is difficult to judge, but I would recommend ScheduledExecutorService and javafx.concurrent to load.