Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Implementing listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Implementing listeners" Watch "Implementing listeners" New topic
Author

Implementing listeners

srinivasan ganesan
Ranch Hand

Joined: Mar 09, 2001
Posts: 54
Our app (built using servlets & jsps) runs on an application server. I have a situation where I need to know if a file is present in a particular location. This file is created after the user logs on and it will be posted in a certain location. I'm trying to implement a listener so that I can give the file to the user after it has been created and posted.
Any ideas on how to to achieve this? Also, if you have any questions, please let me know.
Thanks in advance,
Srinivas
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, you can create a thread that sleeps most of the time, but every second/minute/hour/whatever wakes up and looks for the file. You can check for a specific file name, or use File.listFiles() combined with File.lastModified() to search for any new files in a particular directory.


"I'm not back." - Bill Harding, Twister
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
You can use java.util.Timer and java.util.TimerTask to do as Jim has mentioned.
Or you can use Oberver and Observable Pattern.
Garandi
 
jQuery in Action, 2nd edition
 
subject: Implementing listeners