You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by yo...@darkmag.net on 2003/05/20 14:12:46 UTC

[Half-OT] Background apps in webapp ?

Hail,

I've to developp a small java app for my webapp ; it must check every 10
mins (for example) some data into my oracle database and react according
to some values (still for example, if a date stored in a field is today,
send a mail to a person).

I thought I may build a standalone app, which would run in background. But
i'd like this app to retrieve data from my webapp's web.xml (as you can do
in servlets/tags/snippets with getInitParameter())

Is there a technology which allow such things ? Or should i try to "force"
the parsing of the web.xml file while completely ignoring the webapp &
Tomcat's features ? Or, do you have other ideas ? :)

Thx a lot,

Yogi



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [Half-OT] Background apps in webapp ?

Posted by Tim Funk <fu...@joedog.org>.
If an app needs run every X minutes|hours --> use cron

Parsing xml in java is "easy" (google is your friend). Even perl might do 
what you want (easier, ymmv)

Or using cron to spawn a script (which calls wget) to hit a "protected" web 
page might do the trick.

-Tim

yogi-ml@darkmag.net wrote:
> Hail,
> 
> I've to developp a small java app for my webapp ; it must check every 10
> mins (for example) some data into my oracle database and react according
> to some values (still for example, if a date stored in a field is today,
> send a mail to a person).
> 
> I thought I may build a standalone app, which would run in background. But
> i'd like this app to retrieve data from my webapp's web.xml (as you can do
> in servlets/tags/snippets with getInitParameter())
> 
> Is there a technology which allow such things ? Or should i try to "force"
> the parsing of the web.xml file while completely ignoring the webapp &
> Tomcat's features ? Or, do you have other ideas ? :)
> 
> Thx a lot,
> 
> Yogi
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [Half-OT] Background apps in webapp ?

Posted by Emerson Cargnin <em...@tre-sc.gov.br>.
I made an webapp that needed to check for timed-out users, so I created 
a thread int he init method of servlet, it just works great : )


code snippet:


        UsersPolling poolUsers = new UsersPolling(users, configuracao);
        poolUsers.start();


run method of thread  :

public void run()
{

    //loop infinito dando pooling nos usuarios
    while (true)
    {
        try
        {

            sleep(Integer.parseInt(config.USERSPOOLINTERVAL) * 60000);
            Enumeration usersenum = users.elements();
            java.util.Date agora=new java.util.Date();
            while (usersenum.hasMoreElements())       
            {


                Usuario auxuser = (Usuario) usersenum.nextElement();
                 long 
tempoSemAcesso=agora.getTime()-auxuser.getLastAcess().getTime();
                long 
tempoConectado=agora.getTime()-auxuser.getLoginTime().getTime();

                if 
((tempoSemAcesso)>(Integer.parseInt(config.SERVICETIMEOUT)*60000))
                {
                    users.remove(auxuser.getId());
                    System.out.println("Usuario 
"+auxuser.getNomeUsuario()+" desconectado por timeout 
:"+(tempoSemAcesso/60000)+" minutos");
                    System.out.println("Login : 
"+auxuser.getLoginTime()+" Agora : "+agora);
                    System.out.println("Permaneceu conectado por : 
"+tempoConectado+" Agora : "+agora);                       
                   
                }

            }

        }
        catch (InterruptedException e)
        {
            System.out.println(e);
        }
    }

Ari Suutari wrote:

>Hi,
>
>On Tuesday 20 May 2003 15:12, yogi-ml@darkmag.net wrote:
>  
>
>>Hail,
>>
>>I've to developp a small java app for my webapp ; it must check every 10
>>mins (for example) some data into my oracle database and react according
>>to some values (still for example, if a date stored in a field is today,
>>send a mail to a person).
>>
>>    
>>
>
>	I have written a small servlet, which starts a thread in
>	init method and stops it in destroy method. Then,
>	I have configured web.xml to load this servlet when
>	tomcat starts. 
>
>	In your case the thread's run-method would
>	just sleep for 10 minutes, then do the work
>	and go back to sleep.
>
>		Ari S.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>  
>

-- 
Emerson Cargnin
Analista de Sitemas
Setor de Desenvolvimento de Sistemas - TRE-SC
tel : (048) - 251-3700 - Ramal 3181




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [Half-OT] Background apps in webapp ?

Posted by yo...@darkmag.net.
GREAT idea !
gonna check that right now.

Thx all for your answers, but i'd like it to be as easy as possible for
system backups/restores, so no cron and other subtilites.

YoGi

> 	I have written a small servlet, which starts a thread in
> 	init method and stops it in destroy method. Then,
> 	I have configured web.xml to load this servlet when
> 	tomcat starts.
>
> 	In your case the thread's run-method would
> 	just sleep for 10 minutes, then do the work
> 	and go back to sleep.
>
> 		Ari S.
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [Half-OT] Background apps in webapp ?

Posted by Ari Suutari <ar...@syncrontech.com>.
Hi,

On Tuesday 20 May 2003 15:12, yogi-ml@darkmag.net wrote:
> Hail,
>
> I've to developp a small java app for my webapp ; it must check every 10
> mins (for example) some data into my oracle database and react according
> to some values (still for example, if a date stored in a field is today,
> send a mail to a person).
>

	I have written a small servlet, which starts a thread in
	init method and stops it in destroy method. Then,
	I have configured web.xml to load this servlet when
	tomcat starts. 

	In your case the thread's run-method would
	just sleep for 10 minutes, then do the work
	and go back to sleep.

		Ari S.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [Half-OT] Background apps in webapp ?

Posted by 奕东 方 <fa...@yahoo.com.cn>.
I think that you can write a MDB(Message Driven Bean),which can get initial parameters from ejb-jar.xml,and you can write a standalone app to send message(via jms) to the MDB periodically telling the MDB to check the condition.

yogi-ml@darkmag.net wrote:Hail,

I've to developp a small java app for my webapp ; it must check every 10
mins (for example) some data into my oracle database and react according
to some values (still for example, if a date stored in a field is today,
send a mail to a person).

I thought I may build a standalone app, which would run in background. But
i'd like this app to retrieve data from my webapp's web.xml (as you can do
in servlets/tags/snippets with getInitParameter())

Is there a technology which allow such things ? Or should i try to "force"
the parsing of the web.xml file while completely ignoring the webapp &
Tomcat's features ? Or, do you have other ideas ? :)

Thx a lot,

Yogi



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------
Do You Yahoo!?
"相见不如聊天!不出门一样面对面!网络摄像头对对派送中~赶快用你的雅虎电邮帐号参与吧……