Uladzimir
Uladzimir

Reputation: 441

Non-persistence timer creation on WAS Liberty 17.0.0.3

During migration application to latest Liberty I have some problem with Timer creation. The Timer is created in the @Singleton annotated class in the initialize() method (@PostConstruct). The code is enough easy:

ScheduleExpression schedule = new ScheduleExpression();
setScheduleExpressionTime(schedule);

TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerScheduled = timerService.createCalendarTimer(schedule, timerConfig);

When I deploy the application I get the exception with proposal to create datasource for my persistence Timer. I know - a timer is persistence by default and requires datasource and table to keep it's state, but I ask to create non-persistence.

I was trying to remove persistence timers support from server features (I changed Java EE 7 Full Platform features to Java™ EE 7 Web Profile, so no more ejb-3.2). And now I have exception: CNTR4019E: Persistent timers cannot be created or accessed. Persistent EJB timers are not supported by any of the features configured in the server.xml file.

So, It looks like server ignores my requirement to create non-persistence timer and always trying to create persistence. This code worked before with some old WAS (JEE6), but now I couldn't deploy it.

Someone had this problem? May be I do something wrong? Thank you in advance.

Upvotes: 2

Views: 1085

Answers (2)

Uladzimir
Uladzimir

Reputation: 441

I found out the reason. It is really my fault. I missed one place with timer creation. The timerService is used twice to create timers. First time in the place which I described above and second time inside an event. And second time it looks like:

timerService.createTimer(NB_OF_MILLISECONDS_UNTIL_FIRST_START, null);

Possible for some old WAS versions this code was creating a non-persistence timer, but for now it should be changed to something like:

TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timer = timerService.createSingleActionTimer(NB_OF_MILLISECONDS_UNTIL_FIRST_START, timerConfig);

Be careful while creating timers. :-) Thank you for help.

Upvotes: 0

Andy Guibert
Andy Guibert

Reputation: 42936

I've tested this out locally and it works OK for me. Here is the full EJB and server.xml configuration that I've used for your comparison.

If this does not work for you, you will need to provide more details on how you are creating/submitting your timer as well as more details on server configuration.

EJB class:

@Singleton
@Startup
public class MyEJB {

    @Resource
    TimerService timerService;

    @PostConstruct
    @Timeout
    public void doThing() {
        System.out.println("starting EJB post-construct");
        ScheduleExpression schedule = new ScheduleExpression();
        schedule.second(5);

        TimerConfig timerConfig = new TimerConfig();
        timerConfig.setPersistent(false);
        Timer timerScheduled = timerService.createCalendarTimer(schedule, timerConfig);
        System.out.println("Is persistent: " + timerScheduled.isPersistent());
    }
}

Server configuration:

<server>    
    <featureManager>
        <feature>webProfile-7.0</feature>
    </featureManager>

    <application location="app1.war"/>    
</server>

Upvotes: 2

Related Questions