Advantages and disadvantages among Timer, ScheduledExecutorService, Thread

Hi, what are the exact advantages and disadvantages among using Timer, using ScheduledExecutorService and just using Thread (Thread.sleep(...))?
For the simple task which needs to poll some values by some interval (the interval is not supposed very accurate, maybe about 5 seconds just ok), is it ok for just using Thread, like:
run() {
  while(isRunning) {
     Thread.sleep(5000);
     //do something
}?

jiangyc wrote:
Why using Timer and TimerTask is simpler and better than using Thread directly? Because it handles the rote stuff that's not directly part of your application. Ideally, your code should just be the marginal stuff that's specific to your app; anything else should be in the library you use. The less code the better.
I feel just using Thread doesn't make my code hard to maintain and by far I don't find any performance issue raised by using Thread (in our swing application, there are maybe less than 10 Thread objects which take care of the different polling tasks). It's not a performance issue; it's a code management issue. (Although the chances are good that Timer will have been well-tuned.) The less code you have, the less code you have to wade through to fix bugs, make changes, etc. This might not seem like much when it's a small program, but it adds up. In a business environment where you have huge codebases worked on by dozens of people (many of whom don't work there anymore) it becomes really important to only write what you have to and no more. Maybe if you're doing a small project it's not important, but keeping your code clean a good habit to get into.
And I wonder the base implementation of Timer and TimerTask is not using Thread?Of course it is. That's not the point. The point is that it keeps your code cleaner.
When you use Thread directly, probably the only part that's directly relevant to your program (as opposed to any other program that uses Thread) is the value you're sticking in Thread.sleep() -- the delay. You specify that in the schedule() call to the Timer.
If you keep your use of Thread minimal, then it might not be much bigger than using Timer/TimerTask, but the latter does more, including stuff you'll probably need to add (like ways to cancel the task).
Also, when you do this using Thread, you're exposing the implementation, but when you use Timer.schedule, you're exposing the intent. The latter makes for clearer code.

Similar Messages

  • Advantages and Disadvantages of Dual booting Windows on PXI Device

     
    Hello,
    In solving my previous problem of running a DLL in RTOS I've stumbled upon another solution. But i wanted to know the pros and cons of this before i make the leap.
    I want to install windows on the PXI device so that the NHR DLL files are run inherently on the windows kernel and i have access over my DAQ devices without placing them in the remote target.
    What are the advantages and disadvantages of installing a windows only on the DAQ device and running all my operation from it. Do i loose my real time features? I dont know, I'm really new to LabView and may sound really dumb. Please excuse my lack of knowledge.
    With Regards,
    Khalid.

     
    Hello Bob,
    Thank you for your insightful answer. I also thought this might happen, loosing all the RT features.
    I have another question for you. If i use a RT variant of windows like "Windows Embedded 8", will this make any difference? Can i regain my RT features by it or i have to go with the LabView RTOS.
    I'm pushing towards a windows system because i have to run this DLL file from NHR which is not supported by the LabView RTOS.
    Moreover, I could just install just windows onto the PXI controller. I'm not being able to make it dual boot. Can you guide me towards proper guideline to do so? I looked at the knowledge base file about dual booting, but the instructions dont exactly match with my available options in BIOS setup.
    Any suggestions from anyone is much appreciated.
    With Regards,
    Khalid.
     

  • What are the advantages and disadvantages to cookies?

    Ok, so I am required to interview some expert for a Final in college. I choose to do my final on cookies throughout the different browsers. The downside is that it is nearly impossible to get a one-on-one interview from an expert in this field. This is my next option. So here are my questions, and I greatly appreciate the help.
    1. What are the advantages and disadvantages of cookies?
    2. Where are the cookies stored, and is it possible for someone to access that information?
    3. You hear horror stories of hackers accessing the different cookies saved on a person's computer, and from there gradually piecing together enough information about that person, to hack into nearly every account they have. How probable is this? What safeguards can a person take against this happening?
    Once again, thank you for any help received.

    I attended uni back in the 70's, and as I recall we had to do some actual research for our term papers - like from books in the library, and needed to "document" our research in a footnote for each page.
    I guess times have changed a bit since then I guess - anecdotal evidence is permissible now?
    Here's a search of articles in the Mozilla Developer Network documentation.
    https://developer.mozilla.org/en-US/docs/tag/Cookies

  • What are the advantage and disadvantage of LavView (comprared with C++)?

    Comparing with C++, what's the advantage and disadvantage of LavView? Because now I decide to write a new tool, we can't make sure which language we will use. The old tool was written in LabView environment.

    Visual Basic works pretty well if you would like to have a nice user
    interface and quick development.
    Nam.
    Alvaro Osle wrote in message
    news:3c065673$0$8509$[email protected]..
    > I think it depends on the tool you want to create.
    >
    > For instance, if the aim of the tool is to control different instruments
    > via GPIB or RS-232 and manage the data, I'll definitely go for the LabView
    > choice. LabView is a really powerful software in order to communicate
    among
    > different instruments and process, manage and show the information in the
    > PC. It's easier than C++ to communicate with instruments and many drivers
    > are available.
    >
    > If you don't need to control any external device, I wouldn't use LabView.
    >
    > Alvaro
    >
    >
    > may <
    [email protected]> wrote in message
    > news:[email protected]..
    > > Comparing with C++, what's the advantage and disadvantage of LavView?
    > > Because now I decide to write a new tool, we can't make sure which
    > > language we will use. The old tool was written in LabView environment.
    >
    >

  • Advantages and disadvantages - LSMW

    hi,
    what are the advantages and disadvantages of LSMW. when should we go for LSMW ? can someone update me.
    BR,
    Ravi.

    Hi,
    Advantages:
    1.Code free tool
    2.The entire Project can be downloaded / uploaded at any environment
    3.best for one time  transfer
    Disadvantages:
    1.Not suitable for frequent data transfer
    Cheers,
    Abdul Hakim

  • Advantages and disadvantages of using views ???

    Hi
    What are the advantages and disadvantages of using views in ABAP porgramming ? 
    Thank You

    hi,
    Data about an application object is often distributed on several tables. By defining a view, you can define an application-dependent view that combines this data. The structure of such a view is defined by specifying the tables and fields used in the view. Fields that are not required can be hidden, thereby minimizing interfaces. A view can be used in ABAP programs for data selection.
    More complicated views can comprise several base tables, the individual tables being linked with a relational join operation. If we dont specify the key fields, it takes time to fetch teh results.
    Regards,
    Sailaja.

  • Advantages and Disadvantages of Proxy

    Advantages and Disadvantages of Proxy
    Hi Firends,
                  Could you please tell me the Advantages and Disadvantages of using Proxy, i need them urgently.
    Note: High reward points will be given for each answer

    HI,
    Advantage:
    The advantage of proxy is that it is send directly to the integration engine.There is no processing in adapter engine involved.
    So the processing time is saved since there is no processing in adapter engine involved and that leads to a better performance.This is the biggest adavantage of the PROXY
    Also we can use proxy only when we have SAP WAS>=6.2
    Also it provides Excellent Error handling
    They can be used for both synchronous and asynchronous communication
    Whereas if u go for Idocs they can be used for asynchronous commn and rfc consumes lots of resources
    Disadvantages
    1) You need to write custom code. In case of IDoc scenario, you need to write custom code to post the IDocs.
    2) Debugging may be difficult in some cases...
    Plz rewards points
    Vikas
    Edited by: vikas jain on Jun 23, 2008 6:15 AM
    Edited by: vikas jain on Jun 23, 2008 6:35 AM

  • Advantages and Disadvantages of Idoc

    Advantages and Disadvantages of Idoc
    Hi Firends,
                  Could you please tell me the Advantages and Disadvantages of using Idoc adapter, i need them urgently.
    Note: High reward points will be given for each answer

    Hi,
    If u choose IDOC the data transfer will be done completely by IDOC method. The records will be as Control Record, Data Record & Status Record. Under the InfoIdoc, the data will be stored in segments. The data is safe here & using status redord could identify the status of the transfer.
    some pros and cons....
    1. Limited to 1000 bytes / record.
    2. User cannot access the data as in PSA.
    3. Data Security is more.
    4. Good for less volume of data.
    5.Fast to load, easy processing, low programming for standard IDOC’s
    6.Good knowledge of IDOC processing required, time consuming if changes have to be made to a created IDOC
    7.It cannot be used for SYNCHRONOUS COMMN
    8.Maintence of port and Genration of partner profile is difficult.
    9.ALE configuration steps required for both in XI and SAP-R/3.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b2b4035c-0d01-0010-31b5-c470d3236afd
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d19fe210-0d01-0010-4094-a6fba344e098
    I ) In the case where we encounter a standard IDOC provided by SAP or Situation where a mapping is available or an IDOC as well as a BAPI exits, the approach will be dependent on the specific integration scenarioo......
    for For example, options might be
    1) sending one IDOC at a time
    2) combing multiple IDOCS and sending as a single IDOC.
    3) making one single RFC call, for each business transation.
    4) avoiding multiple calls to the same BAPI / RFC by deploying a wrapper BAPI and sending all records in one call.
    5) Using the proxy and sending all data in one shot and making single calls to the BAPI from the proxy.
    Regards.
    Srinivasreddy
    Thanks
    Srinivasreddy
    Edited by: Srinivas Reddy on Jun 23, 2008 10:36 AM

  • Advantages and Disadvantages of XML over CSV

    Hi friends,
    We have a requirement in our implimentation project. We are implimenting HR module. The company is using SABA for Education and Certification.
    We are implimenting Education and certification in BW and the data for BW will be comming from SABA.
    We had a discussion on thursday about the integration of SABA to BW. We can do it through DBconnect or by using XI and for this there is time and cost involved.
    The techical team has come with some idea where there will give the data in the form of XML or in CSV format.
    I would like to know the advantages and disadvantages of each and also please consider the performance point in view.
    I would also like to know about the things that need to be  considered if we process the data in multiple files.
    Please give me inputs and the answers will be appreciated with valuable points.
    Regards
    Raghav Reddy

    Hi,
    my advice is to go for CSV anytime compared to XML.
    XML is first made available to the BW system via  SOAP ( Simple Object Acess protocol) interface. Next it is updated into the required data targets as before , Via a data source for the myself source system.
    SOAP = XML+HTTP.
    XML cannot be used for mass data. It is only to load small data into SAP BW on a single document level.
    BW provides flat file interface so, there is no all these hassles in case of CSV. go for CSV

  • Advantages and disadvantages of using Caringorm Framework.

    Hi,
    I am new to Caringorm framework.. In our project we need to make discussion whether to use Caringorm framework or a simpler architecture(flex à servicesàServer side) to use
    Please let me know the advantages and disadvantages of using Caringorm framework from your experiences.
    Thanks in advance.

    hi,
    Data about an application object is often distributed on several tables. By defining a view, you can define an application-dependent view that combines this data. The structure of such a view is defined by specifying the tables and fields used in the view. Fields that are not required can be hidden, thereby minimizing interfaces. A view can be used in ABAP programs for data selection.
    More complicated views can comprise several base tables, the individual tables being linked with a relational join operation. If we dont specify the key fields, it takes time to fetch teh results.
    Regards,
    Sailaja.

  • Advantages and Disadvantages of Switching off logging and debugging

    Hello Experts,
    Can you please explain me the Advantages and Disadvantages of Switching off logging and debugging (/SAPAPO/C4)..?
    Will switching these off improve the performance...?

    Omkar,
    Switching off Logging and debugging will improve performance.  However, you will then not have the logs to assist you in troubleshooting problems.  When I am working in a support role on a stable production system, I look at these logs maybe once a week.  When I am developing new functionality, typically in a development client, I look at them many times each day.  You will have to determine if the performance trade-off is worthwhile to you in your business environment.
    It is not usually necessary to have detailed logs, nor debugging, turned on in a stable production system.  I typically leave the 'standard' logging activated for "*" userid. 
    Don't forget to maintain the logs periodically.  Refer to this document for some general guidelines.
    http://service.sap.com/~sapidb/011000358700000715082008E
    Best Regards,
    DB49

  • Advantages and disadvantages of APEX?

    Hey Guys,
    what would you say are the advantages and disadvantages of APEX?
    I am interested in the opinion of you as developer!
    (I know that there are a lot of information given by Oracle......)
    I would be very glad if you can post some short advantages and disadvantages, which I can use in a presentation in front of a group of costumers!
    Thanks a lot,
    Tim
    Message was edited by:
    ehric02

    One disadvantage, IMO, is that it's a extremely weak
    in native support for printing. I have never really understood the discussion concerning print reporting using Apex. I don't even think one should build that into a tool like this. It's a different playground.
    Does Oracle Forms have printing capabilities ? No, there is another "Reporting" tool called Oracle Reports to do that.
    Does the Struts (J2EE) framework have the capabilities to print? No, you would revert to programming (iText) or use a report designer (iReportDesigner with iReports).
    Does Visual Basic have printing capabilities? Not really, you used Crystal Reports for that.
    The point is that Reporting as such can be a really complex matter, especially in corporations. This should be dealt with a true reporting solution.
    My 2cents,
    ~Dietmar.

  • What are the advantages and disadvantages of the Joint operation

    Hi, I am currently trying what out the advantages and disadvantages of the Joint Operation ... any help would be appreciated

    The advantage of join operations are that joins allow
    retrieval or data from more than one table at a
    time.
    A disadvantage of join operations is that the SQL
    statement may be more complicated to write and read
    than multiple simple selects.
    Another advantage is that fetching data from multiple
    tables in a single SQL statement is that using a join
    is likely to be more efficient than using several
    simple SQL statements with procedural logic
    performing the work of the join.
    There are basic three types of join operations in
    Oracle: nested loop, hash join, and sort/merge.
    You can find descriptions of these operations in the
    Oracle Performance and Tuning manual.
    HTH -- Mark D Powell --
    Thanks for the information Mark ... Much Appreciated

  • What are the advantages and disadvantages

    Hi All,
                      What is the use of Master Data Management. And What are the advantages and disadvantages of Master Data Management.
    Thanks,
    Satish.

    Hi ,
    have a look on same thread :
    Re: MDM?
    - An
    Better search before posting .

  • Advantage and disadvantage of using Sharepoint third party themes

    Hi all,
    Am planning to use third party themes and template to complete my development quickly. Can anyone recommend any good sites / vendor for theme available in market.? My project is going to have 25% customization for sure + Multi device- multi
    browser + Multilingual support so do suggest me advantage and disadvantage of themes which your recommending please?
    Thanks in advance
    Regards,
    Subbu

    Hi,
    Using third party themes can save your time, but it is not conducive to the expansion and demand change in the future.
    It is recommend that customizing your own theme if you had enough budget.
    The following links for your reference:
    http://www.hartsteve.com/2013/06/sharepoint-rest-3rdpartythemes/
    http://themeforest.net/
    http://blog.creative-sharepoint.com/2013/05/creating-a-sharepoint-2013-theme/
    Best Regards
    Dennis Guo
    TechNet Community Support

Maybe you are looking for

  • How to display a message box in a UIX JSP page?

    I've a UIX JSP Application with BC4J developed with JDeveloper RC. The problem is that when the user mistakes in the insertion/updating, I'd like to help him displaying a message box or a modal dialog window. In particular, I've the following code: <

  • Index.pdx  Dialog Warning Help

    Today, for the first time, an error (warning?) dialog box opens up when I open some of my PDF files. The files use to open without the dialog box, and now it appears when I open some of my files. After the PDF loads, a dialog box opens which states:

  • Original File transfer from G4 to new G5

    About to buy G5 20" this week - Apple Store says they can do file transfer from my imac G4 to new G5 for me at time of purchase, but cannot transfer any 3rd party apps (Photoshop, Ill, DreamW, Acrobat, Word, etc.). However in users manual it looks li

  • ITunes disregarded all changes i made on the iPhone itself

    here is the problem: I've connected iPhone 4G to my PC. Installed some applications by synchronizing the phone with iTunes. Then, disconnected the iPhone, rearranged some application icons, and removed some applications. When i did next synchronizati

  • Basics on optimizing transmit rate

    I am running 7.3.1 firmware and everything is "working", but I want to have a consolidated list of things to "tweak" in order to maximize transmit rate. I will describe what I currently have set up, and would appreciate any input on other items that