Yes it isīt problem. Here is code.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vyjimky;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Lolek
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
Thread1 vlak = new Thread1();
vlak.k.start();
Thread l = Thread.currentThread();
Thread.sleep(1000);
System.out.println(vlak.j);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class Thread1 implements Runnable
{
private Number ulozeni = new Number();
int i,j;
Thread k;
Vlakno (){
k = new Thread(this,"vlakno");
}
public void run ()
{
i = 10;
ulozeni.setData(i);
j=ulozeni.getData();
}
}
class Number
{
public int i;
private int o;
public synchronized void setData(int olo)
{
this.o=olo;
System.out.println(o);
}
public synchronized int getData()
{ System.out.println(o);
return this.o;
}
}