Which is better TimerTask or Thread????

Hello!
I have a server-client application. Every client that access the server is assigned a corresponding sleep time (the sleep should be done in a separate thread) before proceeding to their "special task". My problem is for example i have 1000 clients then there will 1000 threads (sleeping threads). That is too much waste resources therefore I want to make a ClientManagerThread object which schedules (using TimerTask) the time the clients will proceed to their corresponding tasks.
But Im not sure if TimerTask will take the same amount of resources as the "1 client 1 sleep thread" implementation. Can anybody please tell me Which of the 2 is better to use and why? Or maybe any better solutions?
Thank you in advance!

Sounds like you need some kind of Thread pooling mechanism. 1000 threads is unnecessarily many IMO. Maybe you could stack 'wakeup' times in a data structure, and have a pool of maybe 20 worker threads that look for jobs that are 'ready', execute them, look for the next job, and so on.
Would that help any?

Similar Messages

  • Which is better, Double Buffering 1, or Double Buffering 2??

    Hi,
    I came across a book that uses a completely different approach to double buffering. I use this method:
    private Graphics dbg;
    private Image dbImage;
    public void update() {
      if (dbImage == null) {
        dbImage = createImage(this.getSize().width, this.getSize().height);
        dbg = dbImage.getGraphics();
      dbg.setColor(this.getBackground());
      dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
      dbg.setColor(this.getForeground());
      paint(dbg);
      g.drawImage(dbImage, 0, 0, this);
    }that was my method for double buffering, and this is the books method:
    import java.awt.*;
    public class DB extends Canvas {
         private Image[] backing = new Image[2];
         private int imageToDraw = 0;
         private int imageNotDraw = 1;
         public void update(Graphics g) {
              paint(g);
         public synchronized void paint(Graphics g) {
              g.drawImage(backing[imageToDraw], 0, 0, this);
         public void addNotify() {
              super.addNotify();
              backing[0] = createImage(400, 400);
              backing[1] = createImage(400, 400);
              setSize(400, 400);
              new Thread(
                   new Runnable() {
                        private int direction = 1;
                        private int position = 0;
                        public void run() {
                             while (true) {
                                  try {
                                       Thread.sleep(10);
                                  }catch (InterruptedException ex) {
                                  Graphics g = backing[imageNotDraw].getGraphics();
                                  g.clearRect(0, 0, 400, 400);
                                                    g.setColor(Color.black);
                                  g.drawOval(position, 200 - position, 400 - (2 * position), 72 * position);
                                  synchronized (DB.this) {
                                       int temp = imageNotDraw;
                                       imageNotDraw = imageToDraw;
                                       imageToDraw = temp;
                                  position += direction;
                                  if (position > 199) {
                                       direction = -1;
                                  }else if (position < 1) {
                                       direction = 1;
                                  repaint();
              ).start();
         public static void main(String args[]) {
              Frame f = new Frame("Double Buffering");
              f.add(new DB(), BorderLayout.CENTER);
              f.pack();
              f.show();
    }which is better? I noticed smoother animation with the later method.
    Is there no difference? Or is it just a figment of my imagination??

    To be fair if you download an applet all the class files are stored in your .jpi_cache, and depending on how that game requests its graphics sometimes they are stored there to, so really if you have to download an applet game twice, blame the programmer (I've probably got that dead wrong :B ).
    But, what's wrong with Jars. They offer so much more.
    No offence meant by this Malohkan but if you can't organize your downloaded files the internet must really be a landmine for you :)
    Personally I'd be happy if I never seen another applet again, it seems java is tied to this legacy, and to the average computer user it seems that is all java is capable of.
    Admitidly there are some very funky applets out here using lots of way over my head funky pixel tricks, but they would look so much better running full screen and offline.

  • Which is better in custom self service function SIT or EIT??

    Hi Guru,
    I have requirements of loan request to be through self service,the end of the approval cycle i will use user hook to create loan element entry for the employee.
    I want to know which is better to be used for this function SIT or EIT ?? which is better in validations on submit page level.
    Regards

    Hello,
    Below thread may provide more informations on difference between SIT and EIT.
    Basis of choosing EIT, SIT and Addition Information DFF
    Regards,
    Saurabh

  • Which is better External View OR Database procedure Proxy ?

    Hi Jasmin and Kilian,
    Creation of External View in HANA and consume in ABAP.
    Which is better External View OR Database procedure Proxy.
    Regards,
    Pravin
    Message was edited by: Jens Weiler
    Branched from http://scn.sap.com/thread/3498161

    Hi Pravin,
    that depends on your application logic and use case. There is no general recommendation for one or the other.
    If, for instance, you have input parameters, you would go for a DB procedure proxy, since the external view does not allow to pass input parameters from the ABAP to the HANA column view.
    On the other hand, if you would like to consume the result in an ALV with integrated data access (the "next generation ALV"), you would rather go for an external view... so - like the answer to so many other questions - it depends... .
    Cheers,
      Jasmin

  • Which is better notify() or notifyAll() ??

    Hello ,
    i know that notify() is responsible to wake up on of the threads waiting to access object and notifyAll() responsible to wake up all threads waiting to access same object but what it is the other different between these two methods ?? and which is better ??
    Thanks a lot

    If there are n number of threads in a wait() mode then the notify() method wakes up or sends the notification to the nth thread that went in the wait() mode in the last. So, only the last thread that went into the wait() mode wakes up out of all the waiting threads. However, in case of notifyAll() the notification is sent to all the waiting threads that are waiting. So, any one of them may come out of the wait() mode depending upon the priority and other factors, like the kind of multitasking supported by the operating system( preemptive or collaborative).

  • Which performs better for windows development, bootcamp or parallels?

    I have an imac at home and am using parallels to host a w7 vm, wherein I do some web and db development.  It is quite sluggish at times.  I think i may need to tweak the config to perhaps allocate more ram to it but i'm not sure.  I just picked up a macbook pro gen2 i7 and before I install a w7 vm or parttition i was wondering which is better, parallels or bootcamp?  I do like the interactivity that parallels gives me with respect to files between the w7 vm and lion, but am wondering it that is perhaps the achilles heal when it comes to performance.
    what's the preferred route by other developers out there?
    Thanks!

    that's what i thought.  thanks for confirming.  it sounds like i might be able to use parallels ALSO later on to access the windows bootcamp partition, based on reading another thread.

  • Advice Needed... which is better?

    Hello...  I am not a computer 'genius", but not a complete "computer idiot' either.  I have a question, and then I will give my reasoning, because maybe it matters in the decision.
    Which is better, a PC (Gateway) with 6GB Ram, i5 processor, 1.5TB HD  or an Imac 4GB Ram, i3 processor, 1TB HD??
    Basically, I have had a Dell 2GB Ram desktop for 7 years, which suited me fine. I ran CS3 on it with no problems.  I recently had a virus, and had to swipe my computer, and when I re-installed Adobe, my Premiere Pro will no longer allow me to edit properly (audio plays fine, while video lags and skips around during viewing).  I know it is time to get a new computer either way, and a few friends have told me that I really shouldnt be running Premiere Pro on 2GB of ram, and suggested at least 6GB.
    I found a Gateway for $650 on bestbuy site with the above specs... but then someone I know, told me I would be better with an Imac with the specs above.  Is that possible that a 4GB mac would run better than the 6GB PC?
    also..  will CS3 work on the Windows 7 PC, but if I get Mac system I will be using CS5.
    I use Photoshop, and Premier Pro for simple music video editing (5-6min videos).  I do not do anything major..but want to at least be able to view what I am doing.
    thanks

    While I don't agree that Macs are as inferior as some here claim, for your purposes an i5 iMac is certainly inadequate. The i7 quad core iMac is something else again; it can take up to 16GB of RAM, which is plenty for most applications. The particular i7 CPU in the iMac is also quite capable with a number of performance enhancing technologies on board. The big problem with the iMac, though, is that it comes with only one internal HDD; there is an added SSD option, but in my opinion it's still too expensive. For video you should have at least two internal drives and preferable three or four, as others here have said. External drives are generally slower, even if you use a FireWire 800 port. Sometime this year Apple may add a Thunderbolt port to the iMac, as they have to the MacBook Pro. This will be a game changer for external media, with unheard of flexibility in connectivity and the performance of Fiber Chanel at an affordable price. There are already external RAIDs coming to market with Thunderbolt connections. However, there is no date certain for such an iMac refresh.
    For even semi-serious video you need some heavy iron, whether Mac or PC. There are some great Mac Pros available now with up to 12 cores on two 6 core Intel Westmere processors; however, even though I am a Mac fan, I'm sure you can build or get a BTO Windows PC with comparable specs for less. I suggest a minimum of four modern CPU cores to handle multi-threading and multi-tasking chores. At least two fast internal hard drives, four is preferable. And, of course, the more RAM the better, though this too will raise the price. You may not get the maximum RAM right away; the important thing is that the motherboard be able to support substantial RAM upgrades so that you can grow into it.
    The challenge, even with PCs, is that a number of core technologies are changing right now. SixGb/s hard drives are becoming available but it would take a high-end and relatively new motherboard to support them properly. So, besides the question of which computer to get, you have to consider when to get it. If you need it right now, that narrows your choices somewhat because you cannot wait for these new technologies to come on line.
    The most important thing to consider, though, is not to cheap out. Presumably you will be doing some real work on it, so think of this computer as an investment in your own future. Buy the most computer you can afford and a little bit more. Oh, and there is a new Version of Final Cut Pro coming out soon that will be Intel only and 64 bit capable, so Apple is moving ahead on this front, too. Remember, not all of Adobe's CS apps are 64 bit yet either. It's just one more technology in transition.
    One point I will concede, however, is that Windows has better video drivers than OS X. Even on a Mac, running Windows in Boot Camp delivers better video frame rates than the Mac versions of the same apps running in OS X. So, for reasons of cost and better video support, a Windows PC is probably the way to go. PCs also have it over Macs in the number of options available. If you are not a techie yourself, I agree as well that it is probably a good idea to have someone who is built it custom for you. Of course, with a custom PC you won't get the kind of warrantee that comes from Dell or Apple, but the person who builds it for you will probably be able to service it as well.
    Ultimately, of course, your budget is likely to govern the kind of PC you get more than your preferred specs. But even with Windows PCs you get what you pay for. A cheap PC is just that, a cheap PC. Inexpensive PCs are affordable because they use inferior components. Keep that in mind.

  • Tech Specs of the audio input jack? (which is better, an iMic, or the MBP?)

    Well because the iMic has such a cheap sounding/terrible audio output....
    http://discussions.apple.com/thread.jspa?threadID=2132385&tstart=0
    ....I am trying to figure out which would be better for the audio INPUT?
    I am surprised to see that both the iMic and the combined jack on the 13" MacBook Pro seem to record in stereo, but technical wise, which is better? I DO know that the iMic is better for non-amped mics, that the iMic will pre-amp the signal where as the MBP will only accept line-in signals. So other then that, which is better?
    Thanks,
    Scott

    Well, I sent back the iCrap...I mean iMic. I had to take a loss of $10 but oh well. (stupid apple return policy.)
    Anyways, my solution was to buy a similar adapter off ebay for only $7. This USB interface is not a brand name one, it is one of those "china knock-off's" but it works. The Audio output it a lot louder but still slightly distorts like the iMic. However, the audio input works just fine. So my solution is to use BOTH the external USB interface, and the jack on the MBP at the same time. That will give me the best of both worlds. AND, it only cost $7 and came in 3 days, vs the adapter I bought from apple that coast over $35 and took a MONTH to ship.

  • Songs with the same title, which is better?

    Song titles aren't always unique to one song, there can be many different ones with the same title. This thread is for those kinds of songs. Post them and tell us which is better to you, and why do you think that is.
    For example, I think this song:
    Is better than this one:
    Because I'm a bit more partial to Pulp and Britpop. But I still think Tom Jones' song is great nonetheless.
    Go ahead and give us your opinion!

    For me, I chose two songs called "Living Well; one by American shoegazers Velocity Girl, the other by Texas slowcore group Bedhead. Although I like both, I prefer the Pavement-ish melancholy of the Bedhead song to the sugary rush of the Velocity Girl song. spotify:track:5BrtSevKCfYWuZ6WnBv9Vcspotify:track:1Fu9pnUNBbyTUOsA5ZwsMd

  • Which is better to use: BEx query or Web Application as an iView in portal?

    Hi gurus!
    Are there any experienced opinions, which is better - publish a BEx query in portal or publish a BEx Web Application in portal? Is it easier to alter the layout attributes etc. if I create a BEx Web Application first before publishing?
    What is the way of fixing for example filter item height if I publish BEx query in portal - is there a Web Application that it uses anyhow which I can fix? Or can I use in that case iView -properties in portal?
    Thankful for advice
    Sari

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Which is better for performance Azure SQL Database or SQL Server in Azure VM?

    Hi,
    We are building an ASP.NET app that will be running on Microsoft Cloud which I think is the new name for Windows Azure. We're expecting this app to have many simultaneous users and want to make sure that we provide excellent performance to end users.
    Here are our main concerns/desires:
    Performance is paramount. Fast response times are very very important
    We want to have as little to do with platform maintenance as possible e.g. managing OS or SQL Server updates, etc.
    We are trying to use "out-of-the-box" standard features.
    With that said, which option would give us the best possible database performance: a SQL Server instance running in a VM on Azure or SQL Server Database as a fully managed service?
    Thanks, Sam

    hello,
    SQL Database using shared resources on the Microsft data centre. Microsoft balance the resource usage of SQL Database so that no one application continuously dominates any resource.You can try the 
    Premium Preview
    for Windows Azure SQL Database which offers better performance by guaranteeing a fixed amount of dedicated resources for a database.
    If you using SQL Server instance running in a VM, you control the operating system and database configuration. And the
    performance of the database depends on many factors such as the size of a virtual machine, and the configuration of the data disks.
    Reference:
    Choosing between SQL Server in Windows Azure VM & Windows Azure SQL Database
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • Which is better??????

    which is better?Dam really confused which speaker to buy??
    i currently have a creative m2600.but am not getting enough performance or that feel while watching movies like avatar,step up 3 etc......so am planning to buy a 5.1.......not planning but i have decided to buy a 5.1....so..
    which is better? the 6160 or 6060 or 6100.
    which of these will provide me relly great exprience while playing games and most importantly while whatching hd movies and while listening to music.......
    and other than this what i have to ask is...what is this "db" in speakers. i mean while looking at a speaker specs we can see it..like 65db,85db,75db..etc........
    and when i compared specs of the three speakers i mentioned above i saw that the 6160 has low "db"........why is that?

    The specs is just a guide, you won't be able to tell the slight difference in db using just your ears. Besides, it is just a comparison between the level of a music to the level of background noise, it does not necessary mean which speaker sounds better. If possible, please make a trip to your local electronics store and try out the speakers system yourself.

  • Which is better, Photoshop or Corel?

    Which is better, Photoshop or Corel? I am finding the best one to use for my website [link removed]. Let me know your opinion. Tks all.

    Thank you! I am trying to find the best one for the site [Link removed].
    I used to use Corel before, but now, I am trying to use Photoshop.
    Tk you anyway
    [Removed link]
    Message was edited by: sinious

  • Which is better software for brochures and PDF forms ? Photoshop or InDesign ?

    Which is better software for brochures and PDF forms ? Photoshop or InDesign ? and why ?

    If you are going to be making a lot of brochures, with photos, you probably want both. Photoshop to edit the photos, and InDesign to assemble and layout images with text.

  • Which is better an android or apple

    Which is better getting an android smart phone or an Apple I Phone?

    As the poster Horses 547 said its a matter of personal preference. However I own and use both. Printing via air print is smooth and easy on an iphone. Printing on a android phone is iffy and tedious and you will have to find an app to print since there is no native app to do so. I purchased http://www.printhand.com which costs around $12 from the app store. but it is in my opinion the best printing app out there for android. I use it on my android tablet as well and its great. This company is the maker of the print app on iphones.
    The iphone is a little harder to put your own ringtone on the device. However very easy from the Itunes you put on your computer and hook into.
    Another thing an iphone does is if you use their cloud service or pay for a song it is available on all your ios devices. Iphone, ipad, or ipod or up to five computers registered through itunes on those computers.
    Google play music also can sync with all your android devices.
    Iphone don't have external Micro SD card slots, so the storage on the phone is all you have.
    Iphones use imessage which does not count against your text allotment  to another iphone or ipad user. it send regular text to non iphone users.
    Another thing is Face Time but I found a better program called oovoo at http://www.oovoo.com or in the Google Play Store for free.
    Iphones are paper thin but I have an android that has a larger view area and is also paper thin and light. Depending on the android phone it may have a removable battery, whereas iphones are sealed as are some new androids. I have found the sound for music better on my iphone, and videos are crystal clear. Again on some better androids the music and video is comparable .
    There is really not many differences but it up to the user.
    One last good thing is iphones are updated via Apple, no long waits for OS updates like is done with Android devices, and android devices on Verizon.

Maybe you are looking for