I want to write a program which polls a particular table for new entries and writes them to a message queue
.
I was thinking of writing a thread
which will loop infinitely and try to get database exclusive lock
and thread.sleep()
will be called if lock
is not acquired.
Then after getting lock
if no new records are found in database thread.sleep()
will be called again.
Is thread the best way for this or should something like timer be used?
EDIT: Basically the question boils down to this: If I need to poll an oracle database using java should I write a thread, or something else like a timer/sheduledExecutor/trigger?