Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem accessing Properties value in Timer thread

Posted on 2010-01-11
3
Medium Priority
?
401 Views
Last Modified: 2013-12-17
I'm have issue accessing properties values if I use schedular.. In the below code:
in my init() method I set properties value in setConfigProperties() method. If i call processInvoiceFiles() from the init() method, I can retrieve property value in processInvoiceFiles() method. However if I call  startSchedular(); method and then call  processInvoiceFiles(); inside run method I get no values from the properties object. Any help will really be appriciated



public void init(Properties properties){
                        this.setConfigProperties(properties);
                        //processInvoiceFiles();
                         startSchedular();
                                    
            }
            /**
        * Implements TimerTask's abstract run method.
        */
        public void run(){
          
          System.out.println("Inside Run method of schedular");
          processInvoiceFiles();
          
        }
   
        public void startSchedular(){
              TimerTask runSchedular  = new ASNSchedular();
              Timer timer = new Timer();
              timer.schedule(runSchedular,0, MINUTES);
        }
      
      public void processInvoiceFiles(){
String out_bound_XML=  configProperties.getProperty("OUT_BOUND_XML_FOLDER_TO_BE_PROCESSED");
          }
0
Comment
Question by:AjooAli
3 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26290151
Please post the complete source code.

thanks
0
 
LVL 20

Expert Comment

by:a_b
ID: 26290192
Can you post the complete code so that I can try it out on my local machine? Seems like something is missing.
0
 
LVL 2

Accepted Solution

by:
malaki12003 earned 2000 total points
ID: 26290231
I think your problem is that you try to access to value property before realty it be set. because process of setting  and getting property is running concurrently. so you must grantee that access to property happen after property initialization. a question? "why you need to call processInvoiceFiles() in thread?" you can call it in init method. but if it is really your want then create a boolean variable that is a flag at first set it to false and  at end of  processInvoiceFiles set it to true. and wheneever you want to access to property must check if it is set to true if not you have to itrate in a loop to it set to true.
above solution may cause  busy waiting problem but it is easy a better solution is that you use wait/ notify mechanism in java.  
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question