Have Trouble understanding the runnable interface

Hi
I am new to java programming. I have trouble understanding threading concepts.When I run the below code,Thread3 runs first. I need a small clarification here- I created two thread objects
Thread thread1=new Thread(new RunnableThread(),"thread1");
Thread thread2=new Thread(new RunnableThread(),"thread2");
As soon as I create these objects -Will the constructor with the string argument in the "RunnableThread" class gets invoked. If so why doesn't System.out.println(runner.getName()); get invoked for the above objects. what is the sequence of execution for the below program.
/*************CODE****************************/
class RunnableThread implements Runnable
     Thread runner;
     public RunnableThread()
     public RunnableThread(String threadName)
          runner=new Thread(this,threadName);          //Create a new Thread.
          System.out.println(runner.getName());
          runner.start();          //Start Thread
     public void run()
          //Display info about this particular Thread
          System.out.println(Thread.currentThread());
public class RunnableExample
     public static void main(String argv[])
          Thread thread1=new Thread(new RunnableThread(),"thread1");
          Thread thread2=new Thread(new RunnableThread(),"thread2");
          RunnableThread thread3=new RunnableThread("thread3");
          //start the threads
          thread1.start();
          thread2.start();
          try
               //delay for one second
               Thread.currentThread().sleep(1000);
          catch (InterruptedException e)
          //Display info about the main thread
          System.out.println(Thread.currentThread());
}

srinivasaditya wrote:
Hi
I am new to java programming. I have trouble understanding threading concepts.I'd consider it to be an advanced area.
When I run the below code,Thread3 runs first. I need a small clarification here- I created two thread objects
Thread thread1=new Thread(new RunnableThread(),"thread1");
Thread thread2=new Thread(new RunnableThread(),"thread2");No, this is wrong. You don't need your RunnableThread. Runnable and Thread are enough. Your wrapper offers nothing of value.
>
As soon as I create these objects -Will the constructor with the string argument in the "RunnableThread" class gets invoked. If so why doesn't System.out.println(runner.getName()); get invoked for the above objects. what is the sequence of execution for the below program.did you run it and see? Whatever happens, that's the truth.
%

Similar Messages

  • I have trouble seeing the small icons for the program functions in this tutorial.

    Hello,
    I have my assets from an older site, and want to start a site desktop site in muse. Is there a program ( maybe a book ) that can walk me through this step by step, instead of the Katie's Cafe demo / tutorial?
    The problem with the tutorial is in the dark interface I have trouble seeing the small icons for the program functions.
    I really need to setup a new site as soon as possible, but am not getting there right now.
    Thanks.
    Patricia Goff

    You can download the pdf from here :
    https://helpx.adobe.com/pdf/muse_reference.pdf
    Thanks,
    Sanjit

  • We use Embarqmail from CenturyLink on our home computer.  We can get to our email on our iPod, but we have trouble opening the mail.   When we tap on an email, sometimes they open; most often they don't.  Is there a solution?

    We use Embarqmail from CenturyLink on our home computer.  We can get to our email on our iPod, but we have trouble opening the mail.   When we tap on an email, sometimes they open; most often they don't.  Is there a solution?

    Try a reset by pressing the home and sleep buttons until you see the Apple logo, ignoring the slider. Takes about 5-15 secs of button holding and you won't lose any data or settings.

  • I have trouble setting the trash mailbox behavior. I have set it to delete every month but it has been keeping the trash mails for only about 10 days. Please help.

    I have trouble setting the trash mailbox behavior. I have had it set to delete the messages once a month. But lately it has been deleting my messages every 10 days. I have tried choosing different options to set the trash mailbox behavior but has not been successful. Is there anything I can do? Please help.

    Thanks for that advice @randers4.
    I linked through and submitted my info as a "topic not covered" in the iCloud section. After entering the serial number of my MBP it turns out I wasn't eligible for technical support (though I don't think this is hardware related support) and the final suggestion was to take my computer into an Apple store. I called my local Apple reseller and asked for assistance. The customer service rep was very nice but unable to help, so suggested I call Apple Support on 1300 321 456. I did so and, again, spoke to two very polite and helpful customer service people (I was transferred to security services). I didn't have to be on hold to speak to either rep for more than a few seconds! After trying a few different things, he worked out what was happening...
    So, to cut a long story short, to solve the problem in my OP, all I had to do was log out of iCloud in my System Preferences and log back in using my current Apple ID. [Edited to add that I had to sign out of everything I was currently signed in to with my Apple ID before logging out and in again.]
    Problem solved!
    Message was edited by: NotBaconBits

  • Does anyone have trouble with the iPad booting you off of the internet?  I will be in the middle of something (i.e. Facebook), and it boots me out and I have to sign in again.

    Does anyone have trouble with the iPad booting you off of the internet?  I will be in the middle of something (i.e. Facebook), and it boots me out and I have to sign in again.

    Jon....
    Don't confuse the threads here with 'typical' experience.  Most of the stuff here is from brand new users, and those that have problems, and considering the 30 million pads in use, represent a very small sliver.
    If you are having repeated crashes it is really pretty basic.  You either have a physical problem with your pad, or you are using too much memory.
    The iOS system is supposed to monitor memory, and shut down previously used apps automatically to free up memory for what you are doing now.  That part of ios is not perfect, and if an app introduces an unexpected memory load, sometimes it gets over whelmed.  
    This happens, more often than not, when using safari with multiple windows open on graphic intense sites.  It can also happen with a memory intensive game, and residual apps in the background.
    Double  tap the home key and take a peek at the recently used list, and shut them down completely, and often the problem goes away.
    If the problem persists, you may have a software issue, and a trip to the genius bar may be in order.

  • I have trouble getting the scrubber bar to show. How can I get it to show on my screen?

    I have trouble getting the scrubber bar to show on my screen. Sometimes it's there and sometimes it's not. How can I get it to show on the screen whenever I want. Nothing in my manual answers that question.

    The Users Guide says:
    Additional audio controls
    To display additional controls, tap the album artwork on the Now Playing screen. You can see elapsed time, remaining time, and the song number. The song’s lyrics also appear, if you’ve added them to the song in iTunes.

  • Does anyone have trouble serializing the enterprise version-education?

    Does anyone have trouble serializing the enterprise version (education) by any chance? We can't seem to serialize using the serializing tool. the CC 2014 reverts to a trial...

    Jon....
    Don't confuse the threads here with 'typical' experience.  Most of the stuff here is from brand new users, and those that have problems, and considering the 30 million pads in use, represent a very small sliver.
    If you are having repeated crashes it is really pretty basic.  You either have a physical problem with your pad, or you are using too much memory.
    The iOS system is supposed to monitor memory, and shut down previously used apps automatically to free up memory for what you are doing now.  That part of ios is not perfect, and if an app introduces an unexpected memory load, sometimes it gets over whelmed.  
    This happens, more often than not, when using safari with multiple windows open on graphic intense sites.  It can also happen with a memory intensive game, and residual apps in the background.
    Double  tap the home key and take a peek at the recently used list, and shut them down completely, and often the problem goes away.
    If the problem persists, you may have a software issue, and a trip to the genius bar may be in order.

  • I have trouble viewing the messages app window in OS X 10.9

    I have trouble viewing the messages app window in OS X 10.9
    help me!!

    Define trouble please ...
    What exactly happens ?

  • Does anyone else have trouble with the button on I pad to access other apps

    Does anyone else have trouble with the button on I pad to access other apps

    Hello, Kevandsheila. 
    Thank you for visiting Apple Support Communities. 
    Here are some troubleshooting steps that I could recommend when experiencing Home button issues.  The article below is labeled for the iPhone, but the steps are the same for your iPad. 
    The Home button is slow to respond
    If the Home button is slow to respond when exiting one application, try another application.
    If the issue exists only in certain applications, try removing and reinstalling those applications. Get further assistance in installing and troubleshooting applications.
    If the issue continues, Try turning iPhone off and then on again. If the iPhone will not restart, try resetting it.
    If the issue is still happening, try to restore the iPhone.
    Seek service is the issue is still occurring.
    The Home button isn't working
    Put the iPhone to sleep.
    Wait a couple of seconds.
    Press the Home button.
    iPhone should wake up.
    If iPhone does not wake up, then iPhone should be serviced.
    If the issue persists after all the steps have been processed see the last section labeled issue not resolved. 
    Hardware troubleshooting
    http://support.apple.com/kb/ts2802
    Cheers,
    Jason H. 

  • Trying to understand the Serialization interface

    Im trying to understand the Serialization of objects?
    As an example, I create a Library class that implements Serializable, that stores a collection of Book objects
    If I am only looking at saving a Library object to file, does the Book class require Serialization also or just the Library?
    I have read the API on serialization, no answer there, if it is it's not easy to understand or read into the API...

    There are some really important things to know about when doing serialization. For example one important thing to know about that not is mentioned here is that your serializable classes must define its own private static final long serialVersionUID because if you not do that will you not be able to deserialize (read in) the data you have saved later if you change anything in your serializable class. It is a bit tricky to manage files to which you have serialized different versions of your class, that is versions where you have added more serializable members to the class after you have serialized files. Well, it is not a problem if you don´t care if you have to type in all your saved data again every time you change anything instead of deserialize it (read it) from your file of course :)
    Situations like this may be handled if you define your own (private) writeObject(ObjectOutputStream) and your own readObject(ObjectInputStream) methods in your serializable class but there is a better a lot smarter way to handle this. Use of a serialization proxy! how to use that is described in the excellent book Effective Java 2nd ed. With a serialzation proxy for every serializable version of your class (where a version corresponds to a version of your class with differences in its number of serializable members) may your class deserialize data written from elder versions of your class also. Actually is it first since I read the last chapter of Effective Java that I think I have myself begin to understand serialization well enough and I recommend you to do the same to learn how to use serialization in practice.

  • Do any of you have trouble reading the text on the 15" MBP?

    Does the 1440x900 resolution make it difficult to read the text on the screen?

    Not for me, but my eyes are good at close range for someone in his 60s. Those who are more farsighted and need reading glasses for close work may have more trouble.
    The things to be concerned about are the menus, dialog boxes, and other Finder and OS elements that can't be enlarged except by reducing the display resolution, which blurs everything on the display. In most applications' windows, you can easily change the font size or zoom in on the page as a whole to suit yourself. Ultimately, whether you're comfortable with the screen resolution at its native (maximum) setting is a purely personal decision that only you can make. I strongly advise you NOT to buy any computer whose display is uncomfortable to use at its native setting, because you will be looking at a blurry screen ALL the time if you have to use any LCD display at a non-native resolution.

  • Does anyone else have trouble hearing the person you're talking to half way through the call?

    Hello everyone.  For almost 2 years now I have had this ongoing problem.  I have called Verizon several times, stopped by the store several times and no one has been able to help me yet.  I will be on a call and all of a sudden I can't hear the person talking on the other end but they can still hear everything I am saying.  I have tried many times to figure out if there is something in common about the calls but there never is.  I talk to people that are on land lines, cell phones from various wireless providers, I called them, they called me, day, night, different towns, different states - many, many scenarios.  Same thing all the time.  Sometimes it happens when I'm on the phone for one minute, 30 minutes, one hour - sometimes it never happens.  I used to have the Verizon thunderbolt.  I had it for about 10 months before it started happening.  I put up with it until I was at my 2 year mark and upgraded to an IPhone 5.  One hour after walking out of the store with the new phone it happened and has been happening still for the last year.  I'm not lying when I say I have spent HOURS on the phone with Verizon and their technicians.  The customer service reps always promise to call me back and they say "Don't worry I won't drop the ball.  I'll call you when I get in on Saturday" and blah, blah, blah.  My phone is used for work and it's embarrassing when you have to tell the attorney or anyone else for that matter to call me back because you can hear me but I can't hear you.  I am beyond frustrated and am considering breaking my contract.  Wish I could figure out on here how much that would be.  HAS ANYONE HEARD OF THIS ISSUE BEFORE???  PLEASE HELP..

        I'm sorry to learn that you have endured the audio issues outlined in your post for almost 2 years SusanLM1! This is certainly not normal! Let's get to the bottom of this issue, first please confirm your phone model; your mention that you have the iPhone 5 but your post is on the iPhone 5S forum. Also, share the iOS version currently installed on your phone. What is your ZIP code? Does this happen mainly while you make/receive calls from a particular location (home, office, etc)?
    AntonioC_VZW Follow us on Twitter at www.twitter.com/VZWSupport

  • Does anyone have trouble with the screen disappearing while making a call and trying to turn the speaker on?

    I have to use the speaker portion of my phone whenever I make or take a call.  Sometimes the screen goes out as I'm trying to hit the speaker button. Does this happen to anyone else? And any suggestions how to stop this?

    The iPhone is designed to have the screen go dark during a phone call, since the phone is normally up to your ear and you would not want to be touching the screen with your ear and possibly touching random buttons. This is done by the proximity sensor, which is located near the ear speaker on the phone. When you are reaching to turn on the speaker, it is possible that you are crossing this sensor light and it turns off the screen. I have done this before. If you try reaching from the bottom of the screen, does this still happen? Try to keep your hand away from the top front portion of the phone and see if that helps.

  • TS1741 Does anyone have trouble with the Remote app losing contact with the iTunes library after it has been connected and working fine for a while. If I go to the computer and turn off sharing, then turn it back on, it will relocate the library again.

    My iTunes remote app on my ipad mini will work fine for a while and then it will lose the library. I then have to turn off sharing on the computer and then turn it back on. This will work for a while and then I will have to repeat the process. Help!

    I have just found the problem to be windows firewall on my library PC
    I can only presume there has been an update to windows firewall or iTunes
    all the relevant programs were on the allowed list
    I'm now currently running with firewall turned off on my library PC.
    I'll update when i have found the rogue setting.

  • Have troubles with the filesystem; is this the right forum?

    Diskutility does not show any error on an iMac, SMART should be ok (tested).
    WhatSize running on the iMac and over FW targetmodus shows the Document folder emty (it is not empty, of course). Finder shows the size in both methods with 78GB.
    At this time I have no HD for a backup, should I buy one for sure?
    _______ brg, k.

    I would take a look at the apple hardware test. Your hard drive may be corrupt.
    I'm not fully understanding you, however I can say that clone programs don't always take all system info, for a number of reasons I won't get into, but don't worry about it if your personnel data is their.
    I would just copy your data that you have on your main drive, onto the external. Divide it up well, making sure you know what is what and what is where. Much to the disgust of others here, I would say just wipe and reinstall, put your stuff back (leave it on the external as a backup, you may want to look at a better backup solution) and see if it still happens. If it doesn't, you all fixed, if it does then your hard drive may well be having major issues.
    If your Mac is within warranty, take it for a repair.
    Regards

Maybe you are looking for

  • ABAP Reports

    Hi All ,               I am new to ABAP ,can someone please tell me how to do the following. 1-Created an interactive report for displaying vendor information based on the selection made by the client.The transactions made by the vendor with the clie

  • JAVA installing problem...

    hi. i'm having a problem installing JAVA Virutual Machine on my laptop computer. i get this error message: "The installer cannot proceed with the current Internet Connection proxy settings. Please check the installation notes for more information." C

  • Duplicate activities in network

    Hi, We have a network which has 2 activities having same activity numbers.I dont understand how the user has created 2 activities with same activity no.Now when I try to open this network in display or change mode,system gives error that the network

  • Leading zeros in SAP Script

    hi,   how can i put leading zeros (functionality of FM CONVERSION_EXIT_ALPHA_INPUT) in SAP Script?? b'coz of not having leading zeros in PO number,i m facing problems in fetching the PO header text(text id = F01) using INCLUDE syntax. Message was edi

  • Variable on Characterstic description

    Hi All, My Report Requirement is user want to enter desription as input in the variable screen of the Report. E.g. user want to enter Sales Organisation description in the Variable screen instead of Sales organisation Key. Can anyone help me to get t