Is there a way to figure out what the current thread is?

I've got the following snippet of code:
// create a new thread. If the current thread is not this new thread, return
Thread CountDownThread = new Thread("CountDownThread");
CountDownThread.start();
if (/*CURRENT THREAD*/.getName() != CountDownThread.getName()) {
     System.out.println ("I'm not CountDownThread. I'm leaving.");
     return;
// current thread should be new thread. Therefore start the countdown
CurrTime = InitTime;
while(CurrTime.charAt(0) != '-') {      // go until current time is negative
     CurrTime = C.countDown();       // returns the current time based on the difference between the initial and elapsed time
     setText(CurrTime);                   // display current time in JLabel
C.reset();
setText(C.getCurrTime());What I'm trying to do is get a clock (C) to count down and display the time remaining in a JLabel (this snippet is taken from a method within that very JLabel which I'm extending from javax.swing.JLabel). While it's counting down, I'd like for the program to go off and do other things. Therefore, I'm trying to create a new thread that carries out the task of counting down while the original/main thread moves on to do other things.
Please have a look at the above code and tell me if I'm on the right track. The one thing I don't know how to do is figure out how to tell which thread the current thread is. I'm assuming that both the new thread and original/main one will execute the if statement, the new one after it returns from start() (which I haven't defined). The original/main one will detect that it is not the new thread and return, whereas the new thread will and go on to the while loop. In the while loop, it will count down the clock until it reaches 0, after which point it will reset it and die.
If I'm on the right track, all I need to know is how to detect which thread is currently executing. If I'm not on the right track, what would be the best way to do this?

What? No! No Thread terminates on the return of start(). Those two events are unrelated!Uh... I think you misunderstood what I said.
I didn't say that CountDownThread terminates upon returning from start() (which is what it sounds like you interpreted from me); I said that the thread that CountDownThread creates terminates once CountDownThread returns from start() (i.e. like any other local variable/object). This, of course, assumes that CountDownThread has a Runnable object on which to call its run() method (am I right?), in which case my code above doesn't create a new thread at all (i.e. CountDownThread.start() is executed within the main/original thread) - am I right?
No, run() doesn't call start()! That would be stupid.Again, you misunderstood. I shouldn't need to explain this one. A simple reference to an ordinary dictionary on the words 'former' and 'latter' should suffice :)
Anyway, all joking aside, I have now improved my code and it works! Here's what it looks like:
ClockJLabel.java
package MazeMania.clock;
public class ClockJLabel extends javax.swing.JLabel {
private Clock C;
private ClockJLabelsRunnable CJLR;
public ClockJLabel() {
  C = new Clock();
  CJLR = new ClockJLabelsRunnable();
  setText(C.getCurrTime()); // should be 00:00:00:00
  setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  // need to figure out how to set the size so that it sticks
  setForeground(new java.awt.Color(255, 0, 0));
  setBackground(new java.awt.Color(0, 0, 0));
  setOpaque(true);
// starts the clock counting up indefinitely from 0
public void start() {
  (new Thread(new Runnable() {
    public void run() {
     while(true) setText(C.getElapsedTime());
   })).start();
  //System.out.println("Started clock...");
// starts the clock counting down from an initial time and runs this count down in a separate thread
public void countDown(String InitTime) {
  // initialize the clock
  try {C.initClock(InitTime);}
  catch(java.text.ParseException PE) {
   System.out.println(PE.getMessage());
  // initialize JLabel's display
  setText(C.getCurrTime());
  // prepare Runnable and give it to new Thread. New Thread starts count down.
  CJLR.task = CJLR.COUNTDOWN;
  CJLR.CJL = this;
  Thread CountDownThread = new Thread(CJLR);
  CountDownThread.start();
public Clock getClock() {
  return C;
}ClockJLabelsRunnable
package MazeMania.clock;
import java.lang.Runnable;
class ClockJLabelsRunnable implements Runnable {
public static int COUNTDOWN = 1;
public static int COUNTUP = 2;
// NOTE: this Runnable doesn't test for the proper setting of these variables
public int task = 0;
public ClockJLabel CJL = null;
public void run() {
  Clock C = CJL.getClock();
  while(C.countDown().charAt(0) != '-') {CJL.setText(C.getCurrTime());}
  C.reset();
  CJL.setText(C.getCurrTime());

Similar Messages

  • My hard drive suddenly went from 52 gigs free to 22 gigs- is there any way to figure out what happened?

    my hard drive suddenly went from 52 gigs free to 22 gigs- is there any way to figure out what happened?

    Perhaps this may be of help...
    Where did my Disk Space go?

  • Is there a way to figure out what takes up a lot of memory using Spotlight?

    My 80 GB iMac apparently has 70 of the gigabytes used by various things on the computer, but I am at a loss as to what. My pictures take up about 15 GB and my music about the same, but even with that amount, I can't figure out where the other 50 have gone. I'm thinking there might be something like a large movie I created long ago hidden somewhere but it's not in any obvious place. I was wondering if anyone knows of a way to search for files by size using a method that would perhaps list what is the biggest and therefore taking up all this space because I am almost out of disk... Thanks.
    iMac   Mac OS X (10.4.6)  

    You can use WhatSize to tell you what is using up the space on your hard disk.
    (11787)

  • Is there a way to find out what the exe is?

    I just got my new macbook pro, and copied, uploaded some old cd's of mine.
    problem is, some are videos some are photos and some are documents.
    I managed to title a .jpg on some photos successfully, and they worked. Now I can view them and I saved them that way.
    But the rest, man...(sigh) this is a part of cyber world that I am not used to.
    I don't know weather to title stuff .gif, .sit, .doc...I mean really. Im shooting in the dark over here.
    there are so many .whatever's- how in the heck can you know what to do with these files?
    Is there a way to discern what type of file it is. Besides just a windows exe file that is obviously not recognized by mac?
    thanks everyone.
    -novice.

    If the files were created on a Mac they should have their signature information, even without the filename extension.
    If you have files that don't have any signature information you can try using the command line utility file:
    file /path/to/some.file
    It will look at the file and try to identify it's type. From there you should be able to discern what kind of document it is.

  • My  daughter got an itunes gift card and scratched off the redeem code.  Is there any way to find out what the code was?, my  caughter got an itunes gift card and scratched off the redeem code.  Is there any way to find out what the code was?

    Ny daughter got an itunes gift card.  She scrathed off the entire redeem code, so now she can not redeem it.  Is there any other way to find out the redeem code?

    Try Here  >  http://support.apple.com/kb/TS1292
    If no joy...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact
    And there is this...
    http://www.apple.com/hk/en/support/itunes/store/giftcard/

  • Is there any way to figure out what this transport error is about?

    HI,
    I am getting the following transport error from the log:                      
    u201C R3TRROUT4BHOQZTDNV4U6BLY12MUXO6C6 not found; object also deleted in target Systemu201D                                                                   
    Following the information on this site, I looked through all the tables listed under RSUPD* but could not locate R3TRROUT4BHOQZTDNV4U6BLY12MUXO6C6
    Also, following the help to see RSA1 -> Update rules -> Extras -> Object Data Directory, it shows the update rules was no local.
    The only unique thing about this particular Update Routine, is that the rule source fields include one new field zfield which was an enhancement to 2lis-02_scl. When the Update Rule was transported to Quality, the three fields from the 2LIS, including the zfield (which were mapped in Dev) do not how up in test and hence the transformation becomes u201CXu201D
    The model is:     Infosource (from R3) --> Transformation  ODS
    The transport of the Transformation to Quality ends with warning but when you go to Quality to check, all the 4 Update Rules in the Transformation were ok, except that the 4th update rule, which automatically becomes u201CXu2019 (No Transformation).
    Thanks

    Hi,
    When i try to collect the transformation in Transport connection, I get the following:
    Object '4BHOQZTDNV4U6BLY12MUXO6C6' (ROUT) of type 'Routine' is not availab
    in version 'A'
         Message no. RSO252
    Diagnosis
         You wanted to generate an object with the name
         '4BHOQZTDNV4U6BLY12MUXO6C6' (in transport request ROUT) of type
         'Routine' (TLOGO). This is, however, not available in the BW Repositor
         database. It does not exist in the requested version A. If the version
         is 'D' then it is possible that an error arose during the delivery or
         installation. If the version is 'A' then the Object was either not
         created or not activated.
    System Response
         The object was not taken into account in the next stage of processing.
    But I Can't find it to remove or activate.
    Any more hints?

  • Is there any way to find out what the Ext Id is that is assigned to CRM records

    Whilst there is a lot of confusion as to when and where you use this field and what is the unique record key for some, I have understood that however what I am wanting to find is excatly what is the external ID that was assigned to the CRM record when it was first imported. I can't find any report or other means for getting this info and without it I can't re-import record updates.
    A method for resolving the issues with CRM updates would simply be if the CRM module provided the following
    An export facility as in the Web Apps and Products to simply export the full record with all fields in the same order as required for import
    The ability to attach to that export a slected extended CRM layout
    That he export record also included as the first field the BC CRM ID (this is the one thing we know to be unique no matter what)
    With the above and changes to the import to reference the CRM ID (for existing records) we would indeed be able to apply email address updates to existing records via batch import.
    This seems to be a rather obviuous and simple solution unless I am overlooking something. At present the CRM export / import functions are a serious weakness for large database updates and not having the ability to also import bulk deletes is a major drawback on our ability to maintain and manage the CRM integrity. As it stands, if you have been hit by spammers and have hundreds or thousands of delinquent entries in yoru CRM then you have no choice but to leave them in place and if you used a form that by default subscribes them to your mail list - I gave up on that.
    My last comment relates to the data pass that is done as part of the import - is it not possible to report on all records that will fail to be imported instead of one at a time?  If you want to reduce the load on teh system having a single pass to list all errors and list this so you can read it before the error message fades before your eyes would not be an unreasoonable request. I loath facing imports for this very reason.
    Please BC - when are you going to get around to correcting this major shortcoming in a critical aspect of the solutions we deliver.
    Greg

    Condolences. You can't retrieve the existing password, but you can reset it. See the section on "Resetting the original administrator account password" in this support article:
    http://support.apple.com/kb/HT1274
    Regards.

  • My dad died and I never got his password to update his computer.  Is there any way to find out what the PW is or to change it?

    I need to retrieve the password to my Dads computer, how can I do it? I need to be able to update it.

    Condolences. You can't retrieve the existing password, but you can reset it. See the section on "Resetting the original administrator account password" in this support article:
    http://support.apple.com/kb/HT1274
    Regards.

  • TS2446 Is there a way to find out what your security question answer is?

    Is there a way to find out what your security question answer is?

    Amazing,  I can't find out what app on my phone just ran 388mb of data xfer at 2:44am yesterday while I'm sound asleep yet the LE types can subpoena and search warrant anything I do online and with who and for how long.  Verizon list who I receive phone calls from and make calls to and from where I receive messages and to whom/where I text but can't tell me squat about something that is eating up band width.  I'm sure it's probably some app that is running in the background on my phone. I've just got to figure out what it is and kill it.  I want to drop (cause I don't use it, it's slower than a dial up 1200bps modem)my data plans and save about $50 a month.

  • Is there a way of finding out what has been accessed on my MacBook Pro whilst in the possession of an apple authorised service centre?

    Hi Guys,
    I'm a bit new to this discussion group thing although I've been using Macintosh computers for many years (showing my age).
    I handed my MacBook Pro to be repaired at an authorised apple service centre. When I handed it in they said they needed to keep hold of it to run some diagnostics and requested my password. I've owned various models of mac for the the past 17 years and this is the first hardware problem I have encountered, hence I have never bothered to set up user accounts. 
    As I live in quite a remote part of Sweden I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks) or share some of my personal information (scanned copies of my birth certificate, passport, certificates, photos, etc.) on the web. Is there a way of finding out what activity has taken place whilst they've had it in their possession?
    I appreciate any advice you guys can offer.
    Thanks!
    PS: I've already thought about the 'recently opened' menu and The machine in question is a MacBook Pro 17" (2011) running OS X 10.6.8 (need Rosetta).

    I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks) or share some of my personal information (scanned copies of my birth certificate, passport, certificates, photos, etc.) on the web.
    If you put your info into the computer and hand it to another, you have to assume they will copy everything.
    Why are you putting scanned copies of valuable identity information into a computer than can be hacked, stolen, lost or compromised by a dirty tech?
    Have you lost your mind?
    Is there a way of finding out what activity has taken place whilst they've had it in their possession?
    No. The tech would just deny it if he did, or tell the truth which the answer would be "NO" in either case.
    The employer won't ask that sort of questions without solid proof, less they make a enemy of the employee and/or risk being sued for defamation of character.
    It's not like they bother to have a team of people watching over his shoulder that he doesn't stick a USB thumb drive of your data into his pocket to take home.
    I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks)
    If it's iTunes music, it has your personal ID embedded into the song files. Most IT techs know this though.
    I appreciate any advice you guys can offer.
    Too late now, all you can do is not worry about it.
    Take your personal info out of the machine and if you need it, burn cd/dvd copies, a few USB thumb drives, Iron Keys or self encrypting external storage drives with key and/or keypad.

  • Is there a way to figure out the name behind an Apple ID?

    Is there a way to figure out the name behind an Apple ID?  My oganization uses an iPad as a kiosk.  Somone accessed the iPad, changed the Apple ID associated with iTunes, downloaded a game and set a password to lock up the whole iPad.  We had to completely restore the iPad in order to access it.  When I tried to upload a new app, a different Apple ID popped up, and I'm assuming it was the person who locked the iPad and downloaded the game.  I would like to figure out who owns that account, just so we can not allow that person access to the iPads anymore.
    Is there a way to do this?

    The Apple Support Communities are an international user to user technical support forum. As a man from Mexico, Spanish is my native tongue. I do not speak English very well, however, I do write in English with the aid of the Mac OS X spelling and grammar checks. I also live in a culture perhaps very very different from your own. When offering advice in the ASC, my comments are not meant to be anything more than helpful and certainly not to be taken as insults.
    Perhaps with a court order because the person committed a criminal act. Otherwise it is doubtful that Apple would violate the privacy of a client/account holder just on your word.

  • Is there a way of finding out what lists in sharepoint are being looked up for document templates etc

    Hi,
    I am currently in the middle of setting up SharePoint sites and have come across many lists that have not been updated for a while. I am wondering is there a way of finding out what lists are being used and what lists aren't being used for example I would
    like to find out if a list is being used for a look up.
    Josh
    J Burns

    I don't think there any such option available OOTB, however you can use PowerShell to get such information e.g.
    $web = Get-SPWeb http://localhost
    $f = $web.Lists["Contact"].Fields["Customer"]
    $f.ListsFieldUsedIn()
    $web.Dispose()
    Check this link: http://sharepoint.stackexchange.com/questions/45574/is-a-list-being-used-as-a-lookup-for-some-web-part-in-the-site-collection
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

  • Is there any way to find out what brush is applied to a path?

    I'm trying to write a script: select some paths, run the script, then each path that has a brush applied to it is changed to use a random brush whose name is sufficiently similar to its current brush. The application is pretty obvious - draw a bunch of lines in, say, 'ragged marker 1', then give it some extra liveliness by having five or six 'ragged marker' brushes that get randomly chosen.
    The problem I'm running against is that as far as I can tell, Illustrator only lets Javascript set what brush an object is using with brush.applyTo (artItem), but I can't seem to find any way to find out what path a brush is currently using via JS.
    Am I just not looking in the right place of the Javascript reference, or is this really a thing that only has a setter, with no corresponding getter?

    Just like you said earlier
    3.  Re: Is there any way to find out what brush is applied to a path?
           imagecollection     Apr 7, 2015 6:01 PM  (in response to Silly-V)   
    The skill of scripting in Illustrator is to (due to necessity) find the most difficult way to achieve the simplest of tasks...
    so to retort I say this;
    “I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.”
      ― Abraham Maslow, Toward a Psychology of Being

  • Is there any way to find out what a specific line of data usage was for?

    There is a line on my bill for 97 MB of usage while I was bowling?  I was not using my phone.  How can I find out what it was doing for that specific charge?

    Just like you said earlier
    3.  Re: Is there any way to find out what brush is applied to a path?
           imagecollection     Apr 7, 2015 6:01 PM  (in response to Silly-V)   
    The skill of scripting in Illustrator is to (due to necessity) find the most difficult way to achieve the simplest of tasks...
    so to retort I say this;
    “I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.”
      ― Abraham Maslow, Toward a Psychology of Being

  • Is there a way of finding out what my used GB's were used on?

    sometimes I seem to have up or downloaded far more bits than I think I have... way above my average usage.... I'm running widows 8.1 on an acer laptop and latest android on an asus 7HD.... any suggestions appreciated. thanks Mark

    thanks for reply.. have had alook at the link and it tells me the info I alredy know ie. data used. what I am trying to find out is what the data was used on.Is there a way of getting more information from the internet history on my laptop or tablet?or any other way of finding out what the data was used for?thanks Mark PS perhaps I shoud have said earlier I have an EE mifi dongle that is only used for internet stuff 

Maybe you are looking for

  • SSO to Exchange without user mapping

    I have Exchange configured for collabration groupware integration, and it works fine. I can get my calander entries without a problem when I have a user mapping set for the Exchange Transport. I have SSO enabled using the iis_proxy.dll authenticating

  • Where is the iCloud Drive app icon (folder) in iOS 8? Like the one the show on their website.

    I am running Yosemite on my Macs and updated to ios8 on all of my iPads and iPhone. Yet, I have found no way to access my iCloud Drive folder on the mobile devices. The Apple website for iCloud clearly shows iOS devices viewing an iCloud drive folder

  • How can i get back to iphone software 5.0.1?

    i have on my iphone at the moment the software upgrade 5.1, i was wondering if there was any way to downgrade it to iphone software 5.0.1. any help on this matter would be greatly appreciated.

  • Reportign on Assessment Script repsonses

    Hi, Is there a way to report on or export data collected via assessment scripts such as customer satisfaction surveys, service requests surveys etc? I have checked the reporting side and it appears not. I have downloaded the analysis for excel thing

  • Why don't Yahoo embedded videos work

    videos from youtube, hulu, netflix, etc. work but not yahoo embedded ones. I have the latest version of firefox and adobe flashplayer on windows 7 64 bit. i have tried installing/uninstalling flashplayer and firefox. i also tried loading it in safe m