Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
Join Date: Dec 2009
Posts: 263
Executing a task asynchronously

Hello,
I wanted to use the api competitor for executing a task asynchronously, it is actually sending the mail after sending a form http. such as sending mail may take some time, I would return to the page and allow the sending of mail carried in a separate process, here is my code:
Code:
Executor etor = Executors.newSingleThreadExecutor();
etor.execute(new Runnable() {
   Public void run() {
MailManager.confirmCreation(Instance);
  }
});

Last edited by TechGate : 03-02-2010 at 02:11 AM.
Reply With Quote
  #2  
Old 03-02-2010
Member
 
Join Date: Nov 2009
Posts: 518
Re: Executing a task asynchronously

Hello,
I think the risks are not related to Executors in themselves, but rather to your code. Like any elements that could be used from multiple threads, ensure that everything is thread safe. Clearly he / she should have your code and well on all the objects that are shared by your method (the parameter "instance" to start, but also any static data ...) I think you should think of an alternative for this.
Reply With Quote
  #3  
Old 03-02-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Executing a task asynchronously

Hi,
I think the risk is possible flooding when the threads providers give more tasks to process the thread executor can process sequentially, the queue grows bigger. But it is a particular case depends on the nature of tasks. Yes, even I agree at the above post, as he has mentioned you should look for an .alternative solution for this
Reply With Quote
  #4  
Old 03-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Executing a task asynchronously

Hello,
You must make sure that all this is thread-safe, meaning that all the shared elements are:
- use of thread-safe manner (see class documentation).
- immutable (String, Integer, etc..), because it implies the next thread-safe.
- manually synchronized with your code.
If all of this is implemented in your code, then to some extent your code will be safe.
Reply With Quote
  #5  
Old 03-02-2010
Member
 
Join Date: Dec 2009
Posts: 263
Re: Executing a task asynchronously

Hello,
So this is not a solution to implement without taking into account the rest of the code, the goal was just returning control to the user and let the mail is processed by another thread. I must declare functions synchronized change in StringBuffer, StringBuilder and a little review of the principles of synchronization. If you guys can suggest me some other alternative then it will be appreciated. Thanks in advance.
Reply With Quote
  #6  
Old 03-02-2010
Member
 
Join Date: Nov 2009
Posts: 356
Re: Executing a task asynchronously

Hello,
It depends heavily on your code and how you share data. Every sync is not necessarily the best solution either. You can also avoid the maximum sharing of data to work on local objects up to. There are many ways to do it, it depends on your needs, that is how you want your software or application to work. So, just read on this and then think which logic you will apply to your code.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Executing a task asynchronously"
Thread Thread Starter Forum Replies Last Post
Windows Scheduled Task: Unable to start task. 0x80070005: Access is denied. BCU_AJones Windows Software 3 17-01-2014 10:37 AM
Successor task starts on same day predecessor task ends Riverrock Microsoft Project 3 03-01-2014 11:59 AM
No desktop icons, task manager, mouse or task bar on start up night-13 Operating Systems 2 07-12-2011 10:44 PM
Task Scheduler - task creation error on Windows 2008 Server x64 $Bradan$ Operating Systems 5 29-09-2011 01:03 PM
Windows 7 x64: Error message ?task backgroundconfigsurveyor:The task image is corrupt? Angee Windows x64 Edition 7 31-07-2011 05:47 PM


All times are GMT +5.5. The time now is 09:01 PM.