How can I get the variable with the value from Thread's run method

We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
How can I get the variable with the value?
This is sample code:
public class SampleSynchronisation
     public static void main(String df[])
sampleThread sathr= new sampleThread();
sathr.start();
System.out.println("This is the value from the run method "+sathr.x);
/* I should get:
Inside the run method
But I get only:
Inside*/
class sampleThread extends Thread
     public String x="Inside";
     public void run()
          x+="the run method";
NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

Similar Messages

  • How can I  get System dates  with time scheduler using threads

    how can I get System dates with time scheduler using threads.is there any idea to update Date in my application along with system Date automatic updation...

    What the heck are you talking about and whatr has it to do with threads?
    Current time: System.currentTimeMillis. Date instances are not supposed to be updated.

  • How can i get a macbook with the configration i want from apple retail store so that i can benefit from tax free service at the airport ?

    hi all, i just want to know how can i get a MacBook pro with the configuration i want from apple retail store (in Munich) and not by order it online because in this case i will not be able to benefit from Global blue service for tax free from the airport when i leave Germany. 
    thanks in advance.

    You should have probably found out more specifically from the Apple Store just how you could do it online. The obvious solution is to order it from the Apple Danish website store, but I don't know if they ship internationally.
    http://store.apple.com/dk/browse/home/shop_mac/family/macbook_air

  • How can I set 50 variables with the values that are inside an array?

    Hello,
    I have and array of numbers and an array of strings ( the name of the variables) These values are acquired every time from hardware.
    Now I created a graphical interface with 53 of these variables, and I need to create a link to update them with the correct value.
    Thanks
    Dario
    Attachments:
    Example_insert_53_values_in_53_varialbes.vi ‏23 KB

    Dario,
    you have posted your question to the Profibus forum. As your question is not directly related to Profibus, but to LabVIEW programming, your better should post it to the LabVIEW forum.
    Thanks
    Jochen

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • My laptop died so I've installed itunes onto another PC and my music is all on an external hardive which is connected to the new PC. How can I sync my ipod with the new itunes and get all the music onto itunes?

    My laptop died so I've installed itunes onto another PC and my music is all on an external hardive which is connected to the new PC. How can I sync my ipod with the new itunes and get all the music onto itunes?

    You might consider itunes match for moving CDs you've copied into your itunes library if you dont have a way to use home sharing.
    iTunes match is an optional service offered by apple that costs about $25 a year.  It scans your music library and if it finds music that is already in apple's itunes catalog it'll automatically "unlock"/"store" these in the cloud for you.  Items that it does not find in the catalog it'll upload and store these in the cloud for you and you can download them on your devices.  See http://www.apple.com/itunes/itunes-match/

  • I have the original iPad and when I sync it with my macbook pro in iPhoto the faces are different on both, how can I get them to be the same as on the computer

    I have the original iPad and when I sync it with my macbook pro in iPhoto the faces key photo aren't the same on both devices, how can I get them to be the same as on the computer

    Interesting observation.  Thanks for sharing.
    Did you have a technical support question?

  • HT4847 My phone was stolen.  How can I get my photos off the iCloud with a Snow Leopard operating system?

    My phone was stolen.  How can I get my photos off the iCloud with Snow Leopard.

    Welcome to the Apple Community
    You can't, if the photos are in photostream you need a compatible device, if they are in a backup, you can only use the backup to restore to a new device.

  • How do i remove the Icloud Lock on a Iphone thats Clean and can not get in touch with the oraganal owner

    How do i remove the Icloud Lock on a Iphone that's Clean and can not get in touch with the oraganal owner
    thers no  you cant put a reset tool on your site to reset phones thats not stolen or in lost mode

    it's an anti-theft measure DAH Its Not Stolen SO what the crap Then. I wish thay would Remove it From there Ios and Redo it so it Only Locke if you Report it Stolen  or enter Lost Mode. BC thers A lot of PPL that abuse it.

  • How can i get my IMEI of the iPhone i had before i made an exchange with apple SAV ?

    How can i get my IMEI of the iPhone i had before i made an exchange with apple SAV ?
    There is the serial number of the first phone and the serial number and the IMEI of the new one.
    To unlock my phone i need the IMEI of my first phone, how can i get it ?
    Thanks
    <Edited by Host>

    Try going to your Apple support profile. It may still be listed there.
    https://daw.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/classicLogin?appIdKey= 58ef9db8ff4d201409e7270a68e4408ae1678e1618204c476572a1b5e5fb3518&path&language=U S-EN

  • How can I get iTunes to display the tracks from a CD in their original (album) order?

    To be absolutely honest, I don't really understand what this box is for, so I shall just use it to repeat and expand on my question. (I have already sent a "Feedback" comment on the same topic).
    How can I get iTunes to display the tracks from a CD in their original (album) order?
    It seems to me that there is something very basic wrong with the way iTunes handles CD Tracks.
    Professionally produced CD tracks are seldom if ever in a randomised order. Why then does iTunes seem unable to display the tracks in the order they appear on the original CD source - whether from a personally owned CD or from a download from the iTunes Store?
    Some music demands a specific, non-alphabetic sequence in order to make sense. Why does it seem that iTunes only offers Alphabetic, or reverse alphabetic order - both of which make a nonsense of the original, often intended order of tracks?
    Why not replace the so-called "cover-art" in the bottom left hand corner if the iTunes window - which, while it may look attractive to some, gives the barest of information concerning the original disc, with a list of the original CD tracks in their original order, so that the user can easily reestablish the order in which they should be played.
    As I would expect legibility might be a problem with doing this, why could not the original contents, (in their original order), at least, be displayed when the "cover art" is double clicked-on - the result of which at present gives me an enlarged version of the "Cover Art". While on the subject of the contents of the source disc, what about all the album notes which someone takes trouble to write in order to increase the appreciation of the music on the CD and the listener's general background knowledge of the artists involved. Such notes, it seems to me, have considerable intrinsic value in their own account. I would, I think, normally be prepared to buy such "Sleeve notes" - so long as a "taster" was supplied (as it is for the music) - for something like the cost of a single 'Tune" on iTunes.
    These two aspects let Apple iTunes down enormously, in my opinion. I think that by chopping even quite protracted sequences of music up into bits does no one any favours - except perhaps Apple's already quite substantial bank balance. People have to be aware that two and a half, to three and a half minutes is a very short time to develop a piece of worthwhile music, and that there are many, many composers, not all of whom are alive today who have written music that huge masses of mankind value for the enrichment of their lives and the human condition in general.
    Please make the viewing of iTunes tracks in their correct order by default possible. By all means have the alphabetical variations available as offering a different approach to the music, but not the sole approach to it - PLEASE.
    Frustratedly yours
    Alan Whitaker
    PS I work at my old 24" iMac Intel Core 2 machine which runs OS "Tiger" - because it is more beautiful to look at, the screen is more pleasant to work on, and because, in some ways it is more capable (it will run FreeHand MX without needing a "patch"), than my more recent 21.5" which runs "Snow Leopard". (I don't find it that much slower, either).

    Dear Mike
    Thanks for the support. I am utterly amazed that after all the hype about how good iTunes is that it cannot play a downloaded CD in the correct order, and that what that order should be is not available directly from within one's own iTunes installation. (I know that one can go back to the iTunes Store to check what the order should be, but having downloaded the tracks surely iTunes is clever enough to retrieve this important information.
    My iTunes to differ from yours in that I have also noticed that it seems unable to download copies of my "talking books" in the correct order either. But in my case it downloads them - from a CD - in order, but with the first track downloaded first - so that it appears at the bottom of the column of tracks so that it would get played last! (At least this is, while being inexplicable, a relatively "logical" bit of blundering and because of this is relatively easy to put right!).
    I like many genres of music, some of which are not really programmed except perhaps by the artist performing them. I know that Frank Sinatra was very careful to programme his album songs to obtain a particular effect and in relation to the keys of the music. iTunes presumes to know better.
    Film scores may be totally randomly put together, in some cases, but in others the order is vital to one's appreciation of the music as a whole and how it relates to the plot of the film.
    In symphonic music most works are divided into sections and are conceived by the composer that way. Some individual sections may gain a life of their own if played separately, but they are never complete in the sense that the composer envisaged them without being placed in their proper context.
    Opera and probably most choral music too, is similar except that the words may well become meaningless if the order is changed at the whim of a piece of ill-written computer code, while ballet music has to be heard totally within its sequential context or it becomes meaningless.
    Finally, I would venture that iTunes, by jumbling up the order of the tracks as recorded on a CD, does an immense disservice, not only to the music on a particular CD, but to music in general, by expressing everything in terms of "Songs" - which it seems to interpret as stand-alone items of between 2 and 4 minutes whatever the genre. Even the way the iTunes publicity speaks of how many "songs" it can store instead of how many minutes or hours of recorded sound. This has to be another brick in the wall of "dumming-down" of people's expectations, and the shortening of their attention spans.
    I don't know about anyone else, but I feel betrayed by Apple over this. Perhaps the look, feel and general presentation of an item are not the most desirable features of a consumer product. Maybe it should be judged more on it fitness for the purpose for which it was sold. There is one other possibility - that Apple are trying to redefine "Music" - and that everything that lasts longer than about 3.5 minutes or is in the form of what could for want of a better term be called symphonic in the broadest sense is something else - not "Music" within Apple's new definition, at all!
    Well that's off my chest! now I can get down to creating some sort of order in my iTunes Libraries, knowing that I have to reconsult all the sources in order to confirm the source playing order.
    Anyway thanks again. At least I know that it is not just me
    alanfromthatcham

  • How can I get someone to answer the phone? I'm ready to give VERIZON my business. I sat on the phone for over 20 minutes only to be transferred to "Sales." I then sat on the phone for another 15 minutes!!!! I finally hung up.

    How can I get someone to answer the phone? I'm ready to give VERIZON my business. I sat on the phone for over 20 minutes only to be transferred to "Sales." I then sat on the phone for another 15 minutes!!!! I finally hung up.

    It takes an enormous amount of patience and time to get through to a qualified person.
    My Samsung S5 was locked out and needed a factory reset. Including attempts to achieve this locally, it took over an hour before my problem was even addressed.
    You may be interested in my journey to a very good technical support person.
    First I called the local sales person who had given me his personal business card with the friendly advice to call me with any questions. No answer at about 8:30 am when the business was open. His voice mailbox was full.
    Then I called the local store where I had purchased the phone. The person who answered the phone had learned all the proper stock phrases, but was not familiar with the issue, stated that there were no customers in the store, and I should go there in about an hour when there would be more staff. He suggested dialing *411 from my phone (which was locked). Then he gave me a number to call Verizon, which he had to look up, and it took a minute or so. The number was (removed). That is an internal number for employees and contractors and requires a code to access, obviously not designed for customers' use. He finally cut me off by stating that there were a number of customers in line waiting for his attention!
    After researching all my papers I found 800-922-0204 on my bill. The automated message suggested a hold time of 5 minutes, it took 20 minutes for a Customer Service Representative to pick up, and then I was referred to technical assistance. The hold time was announced to take 5 minutes, after 12 minutes I finally was connected.
    Fortunately I had my computer set up for Skype on a loudspeaker, and was able to do some other paperwork while waiting.
    Persistence was rewarded by having the good fortune to be connected to a very experienced, qualified and patient technical support staff with the name of Thomas (removed). He solved my problem, answered my questions during the process of resetting the phone, and gave an example of courteous and kind customer service that I had never experienced before when dealing with any major internet company.
    >> Edited to comply with the Verizon Wireless Terms of Service <<
    Edited by:  Verizon Moderator

  • How can I get netflix streaming audio, the video is fine but the audio coming through is from the TV(dish)

    how can I get netflix streaming audio, the video is fine but the audio coming through is from the TV(dish)

    It's exactly as I stated. Whenever I try to drag these kinds of loops (ESX24 / software instrument loops? the ones marked in green with the white music note next to them) from the loop browser into the timeline a message comes up saying Audio Not Found for that loop.  And a new track is created automatically when loops are dragged into the timeline, so I'm not creating some other random / synth instrument track so I'm not sure  what the deal is... But perhaps I'll try creating a software instrument track first and then drag the loop into that track and see what happens - maybe there's something with the default settings that automatically creates audio tracks whenever loops are imported?

  • How can I get my books that I download from the Library that are WMA files into my I tunes so I can listen to them

    How can I get my books that I download from the Library that are WMA files into my I tunes so I can listen to them. They have a ton of books but I can only listen to them from my windows media player and I wouldlove to download to my I pod but I have tried everything I can think of it they won't go over.  Someone said all I had to do was copy them over and they would convert but I can't even get them to copy.  Thanks.

    Well it started happening AGAIN with my 2nd IPod. No matter what I did, it Itunes would NOT restore it!
    I finally installed Itunes on my hubby's PC at work and managed to get it restored there.
    Apparently, there must be some sort of compatibility issue with the windows version of Itunes and some other piece of software on my pc.
    And one more important thing! I had to follow the instructions in the other thread that talks about how to correctly uninstall itunes and quicktime, in order to completely eliminate ALL traces of my "first" ipod's existence so it wouldn't demand that I restore it.
    I think the software got "confused" and thought when I connected my 2nd ipod, that it was the 1st and that it still needed to be restored.
    Basically, this is just POORLY written and POORLY tested software!

  • How can I get Mail to capitalise the first letter of a sentence?

    Hello all,
    this is my first time using apple Support Community.  i am a new apple user and have just got my first MacBookPro (its wonderful).  however, i am having some difficulties. 
    How can i get Mail to capitalize the first letter of a sentence and also capitalize 'i' as 'I' automatically?
    Also, how can i get apps like Pages to do the same? and for that matter typing into internet sites like this one? look at the lack of automatic punctuation!!
    Thank you all for any advice and tips you may have. 
    Paul.

    I don't think whether it's easier or not is really an issue.  The problem is that all of these wonderful technologies are taking away our understanding of how to communicate in writing.  It's not a matter of being lazy and not "wanting" to do it, but rather getting to a point where many people "can't" do it.
    I certainly wasn't pointing any fingers.  I use a calculator (or computer if I happen to be on one at the time) to do the most basic math calculations.  I can be out to lunch with co-workers and we have to pull out a calculator to split a bill 4 ways.  I went through school at a time when calculators were not permitted.  So, at one time, I could have easily done all of that stuff in my head.  So far as math goes, my mind has turned to mush a long time ago.  I doubt I could work my way through a long division problem at this point... even if I sat there and really tried.
    Computers were not generally consumer items when I was growing up.  So I didn't grow up in a world with spell checking.  I have certainly grown to use it though and I'm sure my ability to spell properly has diminished somewhat because of it.  I tend to be less careful when typing something out.  If I'm not sure of the spelling on something, I just let my computer either fix it or give me a suggestion for the corrected spelling.  Fortunately, I grew up having to rely on my own ability to spell, so with that foundation, I tend to do fairly well when it comes to spelling.
    We're at a point now where systems can correct grammar and sentence structure.  I think all of these are great tools to help us out, but they shouldn't be used to take the place of actually knowing how to do things.  Having said that, I'm fairly sure that is exactly what will happen.  Just as today, I rely almost entirely on some form of electronics for everyday math, I'm sure people growing up today with expert systems able to correct everything will rely on those equally.

Maybe you are looking for

  • New power adapter for old macbook - It doesn't work!

    Hello! My MacBook is 3 years old. My power adapter got broken at the end where you put it into the socket. Now I bought a new power adapter. The adapters have changed now. The end where you put it into the computer looks now a little bit different. B

  • Arrows not showing up in slideshow, cant control slideshow

    So I have a slideshow that is on one of my pages and the arrows on the two sides will not appear.  Before the pictures all load I can see the arrows behind the pictures but once they the arrows end up behind the pictures.  The pictures rotate normaly

  • Need Flash Player Pop-up Message Suppressed in Quiet Installer

    Hello Flash Player Installer Gurus, Thank you in advance for your help. I am launching the Adobe Flash Player 10 installer from another installer and I am running the Adobe Flash Player 10 installer in quiet mode.  However, even though I am running i

  • Extention Manager CS5 not showing up - help

    Extension Manager CS5 not showing up.  I see the extension manager name and pull-down menu in the finder upper menu, but the app interface disappeared.  When I quit, it crashes. I even re-installed EM, but no luck. Anyone else having this problem?   

  • In App Purchase Bug - SKProduct Request

    Hi, This time I am struggling with two very strange problems. The In App Purchase functionality seems buggy. Problem 1: The SKProductRequest works on one device (iOS version 4.02), but not on the other (iOS 4.2). None of the devices are jailbreaked,