on 10-09-2006 5:45 AM
Hai,
I had a requirement that, When the Database table is updated i need to invoke a java class. Is this possible with maxdb. please give me helpfull suggestions to achieve this requirement.
Regards,
Hi !
You can use two strategies.
1. Set a trigger to table, but in that case all operations you want to invoke must be on DB language. No java here.
2. All the modifications must be done throught java class.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
https://java.sun.com/docs/books/tutorial/deployment/jar/jarclassloader.html
public void invokeClass(String name, String[] args)
throws ClassNotFoundException,
NoSuchMethodException,
InvocationTargetException
{
Class c = loadClass(name);
Method m = c.getMethod("main", new Class[] { args.getClass() });
m.setAccessible(true);
int mods = m.getModifiers();
if (m.getReturnType() != void.class || !Modifier.isStatic(mods) ||
!Modifier.isPublic(mods)) {
throw new NoSuchMethodException("main");
}
try {
m.invoke(null, new Object[] { args });
} catch (IllegalAccessException e) {
// This should not happen, as we have disabled access checks
}
}
*Please reward helpfull answer.
Message was edited by:
Roberto Tagliento
Hai Brandelik,
I thought It would solve my problem.
My actual requiremnt is,
I created web services for Ejbs.
I had one database table in maxdb. If some Entry like "create" inserted in the table I need to call the corresponding web service or class.(Here internally the class or web service may do lot of work, we need hide this delay to the client )
Please Suggest me
This may not be a performance oriented solution, but you can try.
Periodically poll the table to find out if any new records available. The best way is include a new status column and put some constant (like 001 for new record, 002 for processed) when new record inserted and update same status once you process the row.
Regards
Abhilash
Hai Abhilash,
I solved it by writing servlet. in that service method of the servlet , i wrote infineite loop that can read table continuosly at the period of 5 mins.
Its giving me correct out put .
But the servlet is became a killer of performance. can you guide me optimize the servlet or another way of solving the above problem
regards,
Naga raju
Hi Nagaraju,
Why don't you use the Timer class to schedule the task instead of running in infinite loop. See the sample code below..
int numberOfMillisecondsInTheFuture = 10000; // 10 sec
int sleepTime = 100000;
Date timeToRun = new Date(System.currentTimeMillis()+
numberOfMillisecondsInTheFuture);
Timer timer = new Timer(true);//runs as Daemon Thread
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
//Call your java method which checks the availability of the records.
Lets run the thread again after
}
}, timeToRun,sleepTime );
If you properly handle the JDBC code then this will give you best performance as the application will run in back ground thread. You can build UI through Servelt/JSP to start or stop the execution.
Regards
Abhilash
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.