3

I have the following code:

package ejbs;
import javax.annotation.Resource;

import javax.ejb.Singleton;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;

@Singleton
public class timerbackup {

@Resource
private TimerService timerservice;

@Timeout
public void methodTimeout(Timer timer)
{     
    System.out.println("timeout");   
} 
public void settimer(long in)
{       
  Timer timer=timerservice.createSingleActionTimer(in,new TimerConfig());  
} 
}

After deploying the application appeared the error message "EJB Timer Service is not available".

To solve the problem i followed these steps:

  1. Access the glash fish admin console (http://localhost:4848)
  2. Go to Configurations->server-config->EJB Container
  3. Select the tab EJB Timer Service
  4. Then fill out Timer Datasource: with your JDBC Resource (i used "jdbc/projecto_final")
  5. Restart the server

As suggested in Set/configure the EJB Timer Service’s DataSource.

This resulted but after sometime the TimerService stopped working. After deploying the application appears the following error messages:

Severe:  Exception while loading the app
Severe:  Undeployment failed for context /ProjetoEE1
Info:    /file:/E:/formacaoJAVA/2moduloJEE/pratica/projecto_final   /projfinal2/ProjetoEE1/build/web/WEB-INF/classes/_DEFAULT_PU logout   successful
Warning:   EJB Timer Service is not available. Timers for application with id 96332697224871936 will not be deleted

The Set/configure the EJB Timer Service’s DataSource also mention this problem, and present a solution in Glassfish DeploymentException: Error in linking security policy for.

The solutions presented in Glassfish DeploymentException: Error in linking security policy for consists basically in delete some files. The answer more voted suggests basically the following:

  1. Stoped the Glassfish server
  2. Deleted all the content from glassfishhome/glassfish/domains/ yourdomainname/generated
  3. Started Glassfish

I have installed the "GlassFish Server 4.1.1", and this doesn´t work.

The second answer more voted suggests the basically the following:

1.All that's needed to fix this problem is delete the entire OSGi cache under $GLASSFISH_HOME/glassfish/domains//osgi-cache

This also doesn´t work.

What i can do? Any help will be very appreciate

Best regards,

Rafael Costa

Community
  • 1
  • 1
Rafael Costa
  • 51
  • 1
  • 1
  • 5
  • I think timers are very important probably many persons have the same problem, and they don´t know how to solve it. – Rafael Costa Jul 30 '16 at 23:57
  • Why do you think so? First of all you should start by tagging your question correctly. Where in the code you posted you see 'jsf'? I'd suggest tagging it 'ejb' And it seems very strongly GlassFish related, so add that tag to (and remove the jsf tag) – Kukeltje Aug 03 '16 at 21:51
  • @Kukeltje Thank you very much. – Rafael Costa Aug 05 '16 at 13:55

4 Answers4

5

I have solved the "same" problem in

  1. deleting glassfish/domains/domain-name/generated folder completely

  2. building application again

  3. restarting glassfish application

In my case, I have installed a new version of my application after a Pull/Push operation with GIT and my application has stopped to work. So I know that before this new build my application worked well and that nothing has been changed on Glassfish.

I have found some explanation on another following site https://dzone.com/articles/solving-ejb-timer-service-not-available-error-in-g-1

The Glassfish application server uses its embedded JAVADB to persist the state of its available EJB timers. Not setting the data resource for the timer service correctly prevents the EJB timers from being restored and eventually from functioning properly. In this case, normally the “EJB timer service not available” error message is returned. This problem prevents any application that uses an EJB timer service from being started or deployed.

There are two procedures available to overcome such blocking situations:

The first solution is to go to JDBC connection pools and double check the health of the Timerpool connection pool by pinging it. If the ping fails then the connection pool needs to be checked or to be redefined.

If pinging the connection pool is successful, then the problem could be the presence of the EJB timer marker file. A marker file is created whenever a problem occurs during the EJB timer service start-up or restore.

Deleting the marker will solve the problem. The marker file "ejb-timer-service-app" located under as-install-parent/glassfish/domains/domain-name/generated/ejb/. Dont forget to restart Glassfish !

schlebe
  • 3,387
  • 5
  • 37
  • 50
4

Replace

import javax.ejb.Singleton;

With

import javax.inject.Singleton;

It worked for me. I'm using Derby database is it the case for you?

  • Keep in mind that the Class will loose EJB features then (e.g. no longer transactional / no container managed concurrency). See [this answer](https://stackoverflow.com/q/36568344/5223047) for more information. – ltlBeBoy Apr 03 '23 at 10:08
2

I solved the problem. If i remenber, i created a new JDBC resource and a new JDBC Connection Pool.

The following link explains how to create a JDBC resource and a JDBC Connection Pool. General Steps for Creating a JDBC Resource

The JDBC resource and the JDBC Connection Pool can be created using the admin console or the asadmin utility.

The following link explains how to use the asadmin utility.Using the asadmin Utility (I used this utility because in the admin console when i tried to create a JDBC resource and a JDBC Connection Pool appeared an error)

In the admin console, in the created JDBC Resource the field "Pool Name" should equals the name of the created JDBC Connection Pool.

After that i followed these steps:

  1. Configurations->server-config->EJB Container
  2. Select the tab EJB Timer Service
  3. Fill the field Timer Datasource with the name of the JDBC resource.
  4. Restart the server

Any question please feel free.

Best Regards Rafael Santos Costa

Rafael Costa
  • 51
  • 1
  • 1
  • 5
0

Hello I met the same problem if you have glassfish 4.1.1 there is probably an instability in the server with respect to timer. Solution: update glassfish 4.1 to glassfish 5 and deploy the web application in this new server