Does spring garantee visibility of 'sleepInterval' and 'businessLogic' instance variables in case below?
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Service
public class SomeService implements Runnable {
@Value("${sleepInterval}")
private Long sleepInterval;
@Autowired
private BusinessLogicService businessLogic;
@PostConstruct
public void postConstruct() {
new Thread(this).start();
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(sleepInterval);
businessLogic.doSomeBusinessLogic();
} catch (InterruptedException e) {
//handle error
}
}
}
}
I think there should be a visibility problem. But I couldn't reproduce it.