java - Load email using javax.mail -


i using java.mail jar file version 1.4.7

i created window's scheduler load emails email server. scheduler run every 7 minutes. @ end of code, emails loaded, system delete them email server.

this supposes work if previous instance takes more 7 minutes load emails, new instance load same email because first instance have not run code delete email.

i think concurrency issue.

i have tried few solutions:

  1. add synchronized keyword method.
  2. add checkbox named isrun. before instance run method, need verify whether isrun == false. if false, system run method; if true, bypass of code. after instance finishes running method, update isrun checkbox false again.
  3. increase length of time of window's scheduler. run method every 15 minutes instead of 7 minutes.
  4. change method non-static static.

these methods not workable if size of emails large. (possible have lot of attachments.)

do have idea on how solve this?

i presume windows scheduler event fires off new instance of java application. in case need use kind of external locking. perhaps creating lock file. process checks if locking file exists , if not creates 1 , continues. second process detect file , have wait or abort. once process finished removes lock file. need careful of how file locking implemented processes. have implement locking though multiple processes don't check file (at same time), see it's not there , both try create it. shouldn't problem processes won't starting @ same time should considered. examples shown here:

how can lock file using java (if possible)

another solution have java application running , every 7 minutes run update. way synchronization can performed internally. main part of application sit in loop , wait 7 minutes pass , run update routine (method). required kind of daemon thread running. apache has takes bit of work , running.

http://commons.apache.org/proper/commons-daemon/

there option in scheduler not run in parallel. easiest option. in settings tab of task properties @ bottom (win 8). can tell not start or wait if there instance running.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -