Hi Jean-Louis, thanks for your reply. Here's a concrete example:
@Stateless
public class QuartzService {
@Inject
private ServletContext servletContext;
private volatile Scheduler scheduler;
@PostConstruct
public void initialize() {
scheduler = getScheduler();
}
private Scheduler getScheduler() {
try {
return ((StdSchedulerFactory) servletContext.getAttribute(
QuartzInitializerListener.QUARTZ_FACTORY_KEY)
).getScheduler();
} catch (final Exception e) {
throw new RuntimeException("Failed to obtain instance of Quartz
Scheduler", e);
}
}
}
We need to wait until the ServletContext is available before retrieving the
scheduler, but since I'm assigning a variable in a multithreaded environment
I'm not sure if there will be memory visibility issues, or if TomEE has some
way of making sure that the bean's variables are synchronized before putting it
into service.
-- Ed
> On Jan 24, 2022, at 3:42 AM, Jean-Louis Monteiro <[email protected]>
> wrote:
>
> Hi,
>
> What's the goal?
> What are you trying to solve with it?
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
>
> On Mon, Jan 17, 2022 at 12:33 AM Ed Slavich <[email protected]>
> wrote:
>
>> Hello,
>>
>> When a bean instance variable is set in a @PostConstruct method, does the
>> variable need to be declared volatile? For example:
>>
>> @Stateless
>> public class SomeBean {
>> private volatile Foo foo;
>>
>> @PostConstruct
>> private void initialize() {
>> foo = new Foo();
>> }
>> }
>>
>> Or does TomEE provide some sort of guarantee that makes volatile
>> unnecessary?
>>
>> Thanks,
>> Ed