2

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.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
Uladzimir
  • 441
  • 5
  • 9

2 Answers2

2

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>
Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • I think you right and it is my fault, I just trying to find where is my mistake and why it worked before. Looks like there is some other timer which I didn't find yet. May be in some local jar. If it works for you It means this is one reason only. – Uladzimir Oct 30 '17 at 15:11
0

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.

Uladzimir
  • 441
  • 5
  • 9
  • `createTimer` always (and has always) meant to create a persistent timer. Perhaps previously you were running on WebSphere Application Server full profile (rather than Liberty), which supports both persistent and non-persistent timers. – Brett Kail Nov 08 '17 at 11:23