Guide me for best methodology

Hai,

I want to write a service(that means its always running on j2ee server and have a watch on some database tables). the service always watch the tables , if the releveant data occurs ion that table, it will call the required Business App.

I did this by using Servlet . I created an infinite while loop in the servlet I wrote the logic here. it was killing my j2ee server performance. and another problem, if the server restarts we need to invoke the servlet again.

Please help to solve the above problem, Guide me any best scenarios

regards,

Naga Raju

[591 byte] By [NagaRajuMeesalaa] at [2007-10-3 6:02:50]
# 1

Well, you could make the loop sleep most of the time (as much as you can get away with) so it doesn't use too many resources. And you can make your j2ee server (and its servlets) start automatically when the server box restarts. And for that matter, you should probably use something other than a servlet to query the database; servlets are for serving (responding to requests) not independant operation.

But furthermore, I'd recommend that you implement this without a loop, and instead use database functionality. You can set up triggers in the database that cause certain functionality to be invoked when data changes. I'm not certain whether that has to be limited to the database itself, or whether you can then have those triggers then invoke functionality on a possibly different jvm process on a possibly different machine.

I'd recommend that you check your db's manual for triggers and related functionality, and ask around on forums dedicted to your db (this sounds like a very implementation-specific kind of thing). It sounds like the db is driving this functionality so the code ought to be invoked there if possible.

paulcwa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 2

Hai Paulcw,

Triggers are not suitable for my requirements, I am using web services to watch Eneviron ment , and iuse web services to run corresponding business logic.

My real Problem is , when the server started I need to send a request for the Servlet otherwise it will not start serviec method.

Is there any way to invoke the service method of servlet when server started.

Is there alternative java technologies available rather than servlets fulfills my requirement.

regards,

NagaRajuMeesalaa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 3

Set up a Java class (not a servlet) that polls a database view then sleeps if it finds nothing to act on.

If it does find what it's looking for, then it springs into action and calls whatever servlet/service you're looking for. Depending on your DB you can bind Java programs to the DB and they could be invoked by some trigger.

Personally, I'm not so keen on that and I'd prefer the external object polling the "queue" for items of work.

marklawforda at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 4
Hi, trigger seems to be the best way to do that, if the database you are using is Oracle then there is a way to embed java class and write a trigger that will correspond to the method in your java class.
pvr_19a at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 5
Hai Markla,I am Using MaxDb as the database, I dnt know about object pooling,Is there any chance to convert a java class as a services like windows operating System.Give me some more info about class pool.regards,
NagaRajuMeesalaa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 6

I didn't say "pool", I said "poll".

The object just sits there and wakes up every few seconds/minutes/hours and checks some queue for work items.

In this case, it will run a query against your DB. If it finds data of interest (as defined by your view) it acts upon that data (probably setting some flag against the data to ensure it doesn't reappear in the queue).

And yes, you can set up a service that will run your Java program.

marklawforda at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 7
Hai markla,I tried to bound a java class to maxdb database , but i didnt succeed, it doesnt support .How can i setup a service that will run java programregards,
NagaRajuMeesalaa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 8
It's going to be OS-specific. You didn't say what OS this is running under.It sounds like you're building a very fragile system.
paulcwa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 9
Hai,I think so, I am using windows Os , but i need the solution OS independent , give me any alternative best solution which is fit to our requirement , waiting for your reply.regards,
NagaRajuMeesalaa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 10
There is no system-independant way to start a program. That's an OS-level thing.
paulcwa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 11
Hai , Is there any way to start a servlet when the server start?(Service method should be run)please suggest me any other solution rather than a servlet for above problem.regards,
NagaRajuMeesalaa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 12
if oracle, you can use triggers on java code, that then communicate to the outside world via various means, eg jms, rmi, socket, ejb, http, jini.
mchan0a at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 13

Hai,

I am using the Database maxdb ,

My actual requirement is to run a continuous program which will watch a databse table when the table was updated by the client side, I need to do some operations.

So that i wrote a servlet , in service method i wrote a ifinite while loop, , i wrote belonging code over ther.

the problem is, servlet killing the peformance of application

and the servlet is not running when the server restarts,

please help me to solve above two issues

regards,

NagaRajuMeesalaa at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 14
why not just a threaded/daemon running in the background?
mchan0a at 2007-7-15 0:45:07 > top of Java-index,Java Essentials,Java Programming...
# 15
Hai mchan,>>why not just a threaded/daemon running in the background? it sounds wellplease give me complete details to achieve thisregards,
NagaRajuMeesalaa at 2007-7-21 11:23:36 > top of Java-index,Java Essentials,Java Programming...
# 16

> Hai,

>

> I think so, I am using windows Os , but i need the

> solution OS independent , give me any alternative

> best solution which is fit to our requirement ,

> waiting for your reply.

>

> regards,

Right. Let's step back a bit.

What are you trying to do?

What kind of data are you working on?

What do you want to do to that data when it changes?

Where will the solution be deployed?

Is this solution tailored to a given customer/system or is it something that will be deployed independently across many arbitrary systems?

marklawforda at 2007-7-21 11:23:36 > top of Java-index,Java Essentials,Java Programming...
# 17
create a threaded app, use java activation.in the app, keep track of the last modified date column. each time select greater than that date. wrap the rows returned into their objects and post to a jms queue for other interested apps to pic up. note the new latest modified date.
mchan0a at 2007-7-21 11:23:36 > top of Java-index,Java Essentials,Java Programming...
# 18
Hai mchan,give me the link or some more information to write daemon threads.regards,
NagaRajuMeesalaa at 2007-7-21 11:23:36 > top of Java-index,Java Essentials,Java Programming...
# 19
google "thread java"
mchan0a at 2007-7-21 11:23:36 > top of Java-index,Java Essentials,Java Programming...
# 20

> Hai mchan,

>

> give me the link or some more information to write

> daemon threads.

>

> regards,

Look in the API:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html

As you can see, Thread possesses a "setDaemon" method, so you can make it a daemon thread.

Mongera at 2007-7-21 11:23:36 > top of Java-index,Java Essentials,Java Programming...