cancel
Showing results for 
Search instead for 
Did you mean: 

Invoking a java class

Former Member
0 Kudos

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,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hai Eugene,

Can you give me the deatiled Information or use full links to solve this problem, give me some info abt 2 point.

regards,

Former Member
roberto_tagliento
Active Contributor
0 Kudos

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

Former Member
0 Kudos

You can also achieve this using EJB's and calling your class from within the update method...

Enjoy

Former Member
0 Kudos

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

former_member182294
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member182294
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hai Abhilash ,

Thanks for your Suggestion,

I will Try on it and revert back to you

regards,

Naga Raju

Former Member
0 Kudos

Hai Abhilash,

Thanks for your Kind help.

I solved it, Its working Fine.

regards,

Naga Raju

0 Kudos

I'm facing exactly the same issue and I can resolve it using your suggestion.

Thanks and Best Regards,

Steven Nguyen

Answers (0)