Thread run and then start

I'm trying to figure out what is the right answer for a following question:
what will be the result of compiling and running the following program?
public class TestThread extends Thread
     private int i;
     public void run()
          i++;
     public static void main(String[] args)
          TestThread a = new TestThread();
          a.run();
          System.out.print(a.i);
          a.start();
          System.out.print(a.i);
Select one option:
A - Compiler error
B - IllegalThreadStateException is thrown
C - Prints "11"
D - Prints "12"
E - Prints "00"
F - Prints "01"
G - Prints "11" or "12"
H - Print "00" or "01"
I think that correct answer is G however the problem is that don't understand how this code resulting "11" in Eclipse when running "run as java application" and "12" when running "debug as java application".
Edited by: 805011 on 25-Oct-2010 07:48

You're right, the answer is G ... but it's not because of the mode you run the application in. For instance, ...
public class TestThread extends Thread
private int i;
     public void run()
          i++;
     public static void main(String[] args)
          TestThread a = new TestThread();
          a.run();
          System.out.print(a.i);
          a.start();
                //Delay print
          for(int i = 0; i < 1000000000; i++)
          System.out.print(a.i);
}By setting a delay, I consistently get '12'. If I remove the delay, I consistently get '11'. So, are you catching my drift? In addition, if you wanted to make sure that the value of 'i' was always updated before the printout, then I'd recommend implementing something like this ...
boolean notDone = true;
while(notDone){
        if(!a.isAlive()){
          System.out.print(a.i);
          notDone = false;
}Regards,
meherts
Edited by: meherts on Oct 25, 2010 9:10 AM

Similar Messages

  • When I run with my iPhone4, the music just keeps skipping to the next song. I'll start my music, start running, and then the songs keep changing so I can never hear a song. Songs are from iTunes and doesn't happen on iPod. HELP?

    When I run with my iPhone4, the music just keeps skipping to the next song. I'll start my music, start running, and then the songs keep changing so I can never hear a song. Songs are from iTunes and it doesn't happen when running with my iPod. Suggestions?

    Go to SETTINGS - IPOD - and turn off "Shake to Shuffle"...
    John

  • I restarted my ipod touch and it ran out of power half way,now it will charge for one little bar and then start restarting again without charging until it runs out, it also wont show up on itunes, can you help me

    i restarted my ipod touch and it ran out of power half way,now it will charge for one little bar and then start restarting again without charging until it runs out, it also wont show up on itunes, can you help me

    the only other thing i can think of is the put the ipod into recovery mode
    but as itunes cant find it, it may not work
    hold the power button for 3sec's keep holding the power button now also hold in the home buttton the screen goes black
    now let go of the power button keep the home held in the screen goes blue and shows the itunes with the cd and the up arrow with the usb cable, connect to itunes to start recovery mode.
    or take it to an apple store fore them to help with recovery mode but this can take up to 3hrs
    or try out www.ipodsurgery.co.uk

  • Something went wrong. To try again, reload the page and then start the workflow

    We have a SP 2013 farm with Aug 2013 CU. While trying to start an SPD 2013 platform workflow from browser I get an error "Something went wrong. To try again, reload the page and then start the workflow."
    I could also see the following in ULS:
    System.NotSupportedException: Not supported in Windows authentication mode.
    at Microsoft.SharePoint.IdentityModel.SPIdentityContext.Create(SPUserToken token, Boolean
    isShareByLinkGuestUser)
    at Microsoft.SharePoint.WorkflowServices.WorkflowServiceContextExtensions.GetApplicationUserCredentials
    (WorkflowServicesContext context) StackTrace:
    at Microsoft.Office.Server.Native.dll: (sig=35339f9c-8871-4ef1-9118-9c1bd0cb6598|2|
    microsoft.office.server.native.pdb, offset=131CE)
    at Microsoft.Office.Server.Native.dll
    This seems to be a bug and is solved in Mar 2013 PU but I have Aug CU. The web where I have this workflow has classic mode auth. Has anyone come across this error before?
    I have checked the following:
    1. Service
    Bus Gateway and Service
    Bus Manager Broker services are started
    2. Authentication for this web application is Windows NTLM
    -- The opinions expressed here represent my own and not those of anybody else -- http://manojvnair.blogspot.com

    Thank you for the steps.
    I have checked User Profile service and it is started and running fine. The user who is trying to start the workflow (me) has a profile created. I'm not starting wf as system account and my account is not added to web application user policy. Workflow isn't
    even firing when I try to edit list item.
    I tried to edit the list item as system account and workflow started this time. But it does to suspended state with the following message:
    RequestorId: 54f4a912-ab0b-a1f2-0000-000000000000. Details: RequestorId: 54f4a912-ab0b-a1f2-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 401
    {"SPRequestGuid":["54f4a912-ab0b-a1f2-be58-305dd8b6eab4"],"request-id":["54f4a912-ab0b-a1f2-be58-305dd8b6eab4"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"SPRequestDuration":["2"],"SPIisLatency":["1"],"MicrosoftSharePointTeamServices":["15.0.0.4535"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1;
    RequireReadOnly"],"Date":["Thu, 24 Apr 2014 15:32:05 GMT"],"Server":["Microsoft-IIS\/8.0"],"WWW-Authenticate":["NTLM"],"X-Powered-By":["ASP.NET"]} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance
    instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
    WhenI try to start wf I can see the first error:
    System.NotSupportedException: Not supported in Windows authentication mode.    
     at Microsoft.SharePoint.IdentityModel.SPIdentityContext.Create(SPUserToken token, Boolean isShareByLinkGuestUser)    
     at Microsoft.SharePoint.WorkflowServices.WorkflowServiceContextExtensions.GetApplicationUserCredentials(WorkflowServicesContext context) StackTrace: 
     at Microsoft.Office.Server.Native.dll: (sig=35339f9c-8871-4ef1-9118-9c1bd0cb6598|2|microsoft.office.server.native.pdb, offset=131CE)
     at Microsoft.Office.Server.Native.dll: (offset=21B4D
    -- The opinions expressed here represent my own and not those of anybody else -- http://manojvnair.blogspot.com

  • My Satellite L350 keeps switching off and then start up again.

    Satellite L350 keeps switching off and then start up again.
    The fan is free from dust. I reinstalled Windows
    There is a new Battery for 1 year
    If the laptop is off, the battery can be charged. The laptop is operating normally on battery.
    From the moment that the AC adapter is connected, the computer turns off.
    When I use the computer without a battery but with the AC adapter, the computer shuts down. Test with another AC adapter, the computer turns off.
    Could it be that the cable between the motherboard and the DC jack is causing the problem whether this is unlikely ?
    Anyone have an idea to help me with this problem ?

    Dr. Lamp,
    Shut down is not always at the same point. In the beginning this happened from time to time and than more frequently. If i start up the computer now with the AC adapter connected than he doesn't start up completely. He shuts down and reboot or blocked.
    To answer your question, I am able to enter the BIOS settings.
    I bought the Yannec battery here:
    I summarize the tests that I did together:
    Loading battery when computer is off = yes
    Running applications only with battery = yes
    With AC adapter connected = computer shut down and reboot
    Without battery, only with AC adapter connected = shut down and reboot
    With other AC adapter = shut down and reboot
    If it is a problem of the motherboard is it not possible that it can be repaired rather than replaced by a new one?
    Many thanks for your patience
    +Message was edited: link has been removed - commercial+

  • I am trying to burn DVDs from iPhoto slideshows.  My pictures number in the hundreds and we know that iPhoto captures 99 and then "starts over".  This plays fine from the Mac Book but glitches arise on the DVD when playing it on a DVD player.  Any suggsts

    I am trying to burn DVDs from iPhoto slideshows.  My pictures number in the hundreds and we know that iPhoto captures 99 and then "starts over".  This plays fine from the Mac Book but glitches arise on the DVD when playing it on a DVD player.  Any suggestions on how to overcome the 99 "Chapter limitation" that IPhoto has?  Has anyone heard or tried an app called Vilisoft?  I read good things but I am not sure if it will do what I want.
    Jim

    Then use multipel 99 picture slideshows. 
    You can have up to 8 or 9 slideshows per menu.  If you add a sub menu reduce that by 1 and add 8 more to the sub menu.  The top menu can have links to up to 8 or so submenus (depends on the theme) and each submenu can have up to 8 or so slideshows. 
    However, converting a very large slideshow to a QT movie as Terence suggested does not envoke the 99 slide limit in iDVD.  It just becomes a single video/movie file.  So you should not have a problem with exporting at the large size, 720 x 540,
    and dragging the resulting file into the iDVD menu being sure to avoid any drop zones.
    OT

  • Ipod touch screen went black and then started flashing. Then the turn off slide comes up.

    Ipod touch screen went black and then started flashing. Then the turn off slide comes up. Restored multiple times and didn't work. Ipod works with Itunes fine (can put music and podcasts on the ipod), but can't take songs off of the ipod. Using windows xp and everything is up to date. Any ideas of how to fix it?

    I didn't know that it was posted three times. My computer didn't say that it posted anything.
    My ipod still syncs to itunes and I can put podcasts and music on my ipod, but I can't delete songs after I put them on the ipod. When I try to delete songs I try to delete it from the main music list on the ipod. It's also doing all the other stuff that I posted before. The screen will go black and then the power off slider thing shows up for a few seconds, then it'll show the unlock slider bar. Then goes black again. It will also do that when I have the ipod unocked and changing songs or playing a game. I've restored it to the factory default/new ipod and it still does the same thing. I've uninstalled and reinstalled itunes and then restored it again to the factory default and it's still doing the same exact thing. I checked and my computer is up to date.

  • Something went wrong. To try again, reload the page and then start the workflow, error on starting a workflow

    i have already create a custom workflow with sharepoint designer and checked for error and it seem fine. i published it on my document library so apprear the first issue : the column that contain the name of my workflow apprear and the link to start my workflow(contain
    the name of my first stap) doesn't appear. the second problem is that when i tried to start the workflow manually on a specific document i get an alert : Something went wrong. To try again, reload the
    page and then start the workflow
    i tried : -restart service bus message broker -restart service bus gateway -recycle workflowMgntpool -flushed the dsn resolver cache and the problem still occure
    on uls log viewer it seems to be an error on w3wp.exe process
    the workflow history is empty

    Hi Mokhtar,
    For your first issue, when you publish a workflow to your document library, only after you start the workflow, then the link to go on the workflow(contain the name of the workflow stage) will appear.
    For your second issue, my understanding is that you got an error when you manually start a SharePoint Designer 2013 Workflow.
    Please go to Administrative Tools->Services, make sure the following services are started.
    Workflow Manager Backend
    Service Bus Message Broker
    Service Bus Gateway
    Windows Fabric Host Service
    Here are similar posts for you as a reference:
    https://social.msdn.microsoft.com/Forums/office/en-US/12f8ae26-6889-4227-a3fc-dd29a38230a6/something-went-wrong-to-try-again-reload-the-page-and-then-start-the-workflow?forum=sharepointcustomization
    http://community.office365.com/en-us/f/154/t/277480.aspx
    If the issue still exists, please check Event Viewer to check more information about this issue.
    http://msdn.microsoft.com/en-us/library/jj193526(v=azure.10).aspx
    I hope this helps.
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Hi, I have connected my iPhone 5 to iTunes, backed it up and then started the update but there was a problem, now my phone will not work, it asks to restore factory settings which I have tried 3 times, each time it says the device has an unknown error.

    Hi, I have connected my iPhone 5 to iTunes, backed it up and then started the update but there was a problem, now my phone will not work, it asks to restore factory settings which I have tried 3 times, each time it says the device has an unknown error and the phone switches off.  Please help.

    Same thing happened with my iPhone 4S - no one is any help.  Thanks Apple for such a crappy update!  I've called Apple, they say the SIM card needs replacing, I go to my service provider they tell me nothing wrong with the SIM card - provider tells me I now need a new phone.  Sheesh!  If someone has a solution to this it would be greatly appreciated.

  • TS3682 I started updating my iPhone 4, but it went black screan and then started turning on and off non stop. I tried to hold the two buttons, but nothing different happened. Please, help! What should I do?!

    I started updating my iPhone 4, but it went black screan and then started turning on and off non stop. I tried to hold the two buttons, but nothing different happened. Please, help! What should I do?!

    First see if placing the iPod in Recovery Mode will allow a restore.
    Next try DFU mode and restore.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    If not successful then time for an appointment at the Genius Bar of an Apple store. You are not alone with this problem.

  • I am trying to download and install OSX Mavericks but everytime i input my Apple ID it keeps asking to review my account and then starts looking for credit card info, I do not have a credit card, also I thought OSX Mavericks was free, some help please.

    I am trying to download and install OSX Mavericks but everytime i input my Apple ID it keeps asking to review my account and then starts looking for credit card info, I do not have a credit card, also I thought OSX Mavericks was free, some help please.

    Yes I know it's free, but Im trying to find out how to download it and install, but I keep getting account review and asked for CC details as I have no CC I can't get the download or install it, any help please, what i don't understand is why would I be asked for CC details if it is a free download ?? i just want to know is there anything I can do.

  • Just got a new Iphone 5s.  On my Iphone 4 I had to double click to show what apps were running and then to hold my finger on an app to deactivate it.  Do you need to deactivate the apps on the 5s?

    Just got a new Iphone 5s.  On my Iphone 4 I had to double click to show what apps were running and then to hold my finger on an app to deactivate it.  Do you need to deactivate the apps on the 5s?  If so how do you do it. 

    Double tap the home button to reveal the "Recently used Apps" then slide the App preview (not the icon) upwards to quit the App.

  • Delete all photos and then start new library

    I got too many pictures [119,266] and want to use a smaller library
    How do I delete and then start a new library

    drag the Photos library to the trash and empty it then launch Photo and create a new library and import the photos you want
    LN

  • My iPhone constantly shuts down and then starts again automatically, and after about 1 or 2 min. again. Is there a way to reset or something?

    I've an iPhone 3 and it happend for the first time yesterday. I had to shut down my phone for a theatershow, and when I started my phone again after the show, it constantly shut down and then started again... Is there a way to delete something or something? 'cause it's very annoying! Already thanks!

    Your contacts should still be on whatever program you sync your iphone to (i.e. Outlook, address book).
    The iphone is not a stand alone device. It is designed to be synced with a computer. If you have not been syncing with a compatible program, then you are out of luck. Your contacts are not included in the back-up because it is meant to be synced with your computer.
    "Although iTunes backs up most of your iPhone and iPod touch settings, downloaded applications, and other information (Contacts, calendars, notes, images in the Camera Roll), your audio, video, and photo content are not included in the backup."
    http://support.apple.com/kb/HT1414

  • After installing OS X Mavericks on myMacBook Pro the Canon IRA 6055 printer gives me "Open error. Switch the printer off and on, and then start the print job again.: 16013" Any sugestions?

    After installing OS X Mavericks on myMacBook Pro the Canon IRA 6055 printer gives me
    "Open error. Switch the printer off and on, and then start the print job again.: 16013"
    Any sugestions?

    This is the new problem
    I pinged the ip address and i looks to be working
    So I'm not sure how to procead
    I nstaled the lates driver package also

Maybe you are looking for

  • In settings under general and in restrictions I'm trying to disable in app purchases but it is asking for a password but I don't remember setting up a password.  What can I do?

    How many attempts do you get before you have an issue in settings under restrictions while trying to turn off in-app purchases?  It's asking me for a passcode but I don't recall ever having a passcode.

  • Desktop 6.2 install hangs on new laptop

    I just got a new laptop with Vista Home Premium 64bit.  I downloade the Desktop 6.2 and I've turned off the user account settings.  The installshield wizard opens and goes through the initial steps that you would expect (agreement terms, typical inst

  • Solaris 8 kernel rebuild

    Hi, Using solaris 8 source foundation cds, I am trying to build the solaris 8 os environment. But I found that there is very little documentations regarding to compiling the kernel source plus commands and libraries out there. I have a feeling like t

  • Message Control changes in ps

    Hi Experts.. How can check the message control changes in PS Cycle ...can anyone help me .... Like when budget is exceeded from where the message "Error in commitment check " is come ....where I can see this in system .... Thanks & Regards Rama Shank

  • Doubt in program

    hi to all help me plz i am doing program in java description of my program 1. i created start date and end date, it has to compare, then the dates has to go to the database, 2. in databse i created a table called holidays(in holiday table there is a