running a parallel polling thread when the webapp gets deployed

classic Classic list List threaded Threaded
7 messages Options
tmp
Reply | Threaded
Open this post in threaded view
|

running a parallel polling thread when the webapp gets deployed

tmp
is it possible to run a polling method after the webapp was deployed on my server?
i need it to check the database every x minutes.

thanks!
tmp
Reply | Threaded
Open this post in threaded view
|

Re: running a parallel polling thread when the webapp gets deployed

tmp
perhaps i have to get more specific :)

i have a root resource A.
this resource is called whenever a client tries to access the resource. if i instantiate a class B in the constructor of the resource A, this class will be instantiated every time a client accesses my webapplication.

what i need is a class that is instantiated only once (when the webapp is deployed) and runs all the time.

why:
the resources of my webapplication write into a database. now i need a mailing service that sends emails according to the data in the database. so i need only one instantiation of the mailing service that polls the database all the time.


do you have any ideas, how i can achieve that? thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: running a parallel polling thread when the webapp gets deployed

Marek Potociar
You may want to consider using some additional enterprise features of
JavaEE container, such as timer service:
http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html

Also, you should consider sending your follow-up questions to the
[hidden email] rather than the old & deprecated
[hidden email] mailing list... :)

HTH,
Marek

On Fri 10 Feb 2012 10:57:42 AM CET, tmp wrote:

> perhaps i have to get more specific :)
>
> i have a root resource A.
> this resource is called whenever a client tries to access the resource. if i
> instantiate a class B in the constructor of the resource A, this class will
> be instantiated every time a client accesses my webapplication.
>
> what i need is a class that is instantiated only once (when the webapp is
> deployed) and runs all the time.
>
> why:
> the resources of my webapplication write into a database. now i need a
> mailing service that sends emails according to the data in the database. so
> i need only one instantiation of the mailing service that polls the database
> all the time.
>
>
> do you have any ideas, how i can achieve that? thanks in advance
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/running-a-parallel-polling-thread-when-the-webapp-gets-deployed-tp7269447p7272149.html
> Sent from the Jersey mailing list archive at Nabble.com.
tmp
Reply | Threaded
Open this post in threaded view
|

Re: running a parallel polling thread when the webapp gets deployed

tmp
thanks alot!

that seems to be exactly what i was searching for.

unfortunately i cannot get it work.
i just added a new method to my resource class:

@Schedule(second="*/5",minute ="*", hour="*", info="every 5s")
    public void automaticTimeout() {
        System.out.println("HELLO TIMER");
    }

when i start the webapplication, nothing happens.
is there anything missing?
Reply | Threaded
Open this post in threaded view
|

Re: running a parallel polling thread when the webapp gets deployed

Marek Potociar
First of all, you are still using the old Jersey email alias... ;)
Also, I think that Jersey forum is not the right place for discussing
EJB timers. You should direct your question towards the forums of the
JavaEE application server you are using. (Since you are not mentioning
what application server are you running on, there is also a possibility
that your AS does not support all JavaEE features...) Try e.g.
GlassFish ( http://glassfish.java.net ) to get full JavaEE feature
support.

Marek

On Fri 10 Feb 2012 04:10:50 PM CET, tmp wrote:

> thanks alot!
>
> that seems to be exactly what i was searching for.
>
> unfortunately i cannot get it work.
> i just added a new method to my resource class:
>
> @Schedule(second="*/5",minute ="*", hour="*", info="every 5s")
>     public void automaticTimeout() {
>         System.out.println("HELLO TIMER");
>     }
>
> when i start the webapplication, nothing happens.
> is there anything missing?
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/running-a-parallel-polling-thread-when-the-webapp-gets-deployed-tp7269447p7272934.html
> Sent from the Jersey mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: running a parallel polling thread when the webapp gets deployed

Glen Mazza
Marek, you work for Oracle, can't you have someone unsubscribe everyone
from the old email list and reregister them for the new one?

Glen

On 02/13/2012 03:51 AM, Marek Potociar wrote:

> First of all, you are still using the old Jersey email alias... ;)
> Also, I think that Jersey forum is not the right place for discussing
> EJB timers. You should direct your question towards the forums of the
> JavaEE application server you are using. (Since you are not mentioning
> what application server are you running on, there is also a possibility
> that your AS does not support all JavaEE features...) Try e.g.
> GlassFish ( http://glassfish.java.net ) to get full JavaEE feature
> support.
>
> Marek
>
> On Fri 10 Feb 2012 04:10:50 PM CET, tmp wrote:
>> thanks alot!
>>
>> that seems to be exactly what i was searching for.
>>
>> unfortunately i cannot get it work.
>> i just added a new method to my resource class:
>>
>> @Schedule(second="*/5",minute ="*", hour="*", info="every 5s")
>>      public void automaticTimeout() {
>>          System.out.println("HELLO TIMER");
>>      }
>>
>> when i start the webapplication, nothing happens.
>> is there anything missing?
>>
>> --
>> View this message in context: http://jersey.576304.n2.nabble.com/running-a-parallel-polling-thread-when-the-webapp-gets-deployed-tp7269447p7272934.html
>> Sent from the Jersey mailing list archive at Nabble.com.


--
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza

tmp
Reply | Threaded
Open this post in threaded view
|

Re: running a parallel polling thread when the webapp gets deployed

tmp
In reply to this post by Marek Potociar
Thanks for your help again!

I tried it 10 times to subscribe for users@jersey.dev.java.net but i'm getting no subscription response.. so i have to use the old adress ;)

I am using the tomcat-maven-plugin to deploy my webapp.
Do I have to register the class that uses the @Schedule annotation in my web.xml explicitely?

Here is my actual web.xml: http://pastebin.com/EamiEeF7
And here is the pom.xml: http://pastebin.com/52KQzM9A

It took me a long time to get the tomcat-maven-plugin running with https and the database connection. So I dont know if it is easy to switch to glassfish instead of tomcat. Do you have experiences with that?

All I need is to start a polling thread as soon as the webapp gets deployed. Perhaps I dont need EJB for that? Isn't there a possibility to achieve this with jersey?

Thanks again for your help!