How to set the running time of Thread??

Hello all
i am new and fresh student to learn Java.
i want to set a limit time to run a thread.

public void interrupt()
Interrupts this thread.
First the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.
If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.
If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.
If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.
If none of the previous conditions hold then this thread's interrupt status will be set.
Throws:
SecurityException - if the current thread cannot modify this thread
to quote the api
but in your case Aldaris it would have no effect
but if you wrote the code as..public void run(){
while(!interrupted()){
  System.out.println("Pete_The_Hat");
}then it would break the loop :-)

Similar Messages

  • How to disable the run-time popup menu in the sequence display on TestStand Operator Interface, that allow the use to skip the test?

    How to disable the run-time popup menu in the sequence display on TestStand Operator Interface, that allow the use to skip the test?

    Hello,
                  Regarding the skip/force pass/force fail options, when I set the ControlExecFlow to True in Teststand 3.1 and 3.5, in the Sequence Editor the menu options for skip/force pass/force fail are not active for Technician but, when I launch the Operator Interface logged with Technician the options are active. The problem is that if the technician sets one step to one of these options, and change the user to Operator, the test step remains skip/force pass.
                  Is there any possibility without modifying the Operator Interface (at programming level), to reload default values of the steps when changing the user to Operator?
    Thank you,
    Best regards,
    paio

  • How to shorten the running time of NXT brick (TETRIX & MATRIX toolkit)

    Hi
    How to shorten the running time of NXT brick ?
    (TETRIX & MATRIX toolkit running time)
    Software is LabVIEW 2012 for LEGO MINDSTORMS
    Thanks.
    Solved!
    Go to Solution.
    Attachments:
    TETRIX_Toolkit_running_time.vi ‏20 KB
    MATRIX_Toolkit_running_time.vi ‏13 KB

    Hi 40123157,
    You are using the module in an appropriate way, and there is no easy way to improve the loop iteration time beyond what you have done. Here are my suggestions:
    1) i2c commands do take a long time. In your application, it may speed up if you only execute Move Motors only when the motor speed has changed.
    2) For this particular example, you are not using the output of Motor Status. If this VI doesn't need to execute it may be removed.
    3) If you must speed up execution beyond this, as an advanced user of LabVIEW, you can create a copy of the Move Motors VI and modify it as you choose. All you have to do for the 'DC Motors' input is use cluster to array on the cluster, as shown below. I think you can speed it up by executing all setup before the loop (set connection type and setup sensor), and removing calculate power value if you're only sending values between -100 and 100.  
    4) Drawing to the screen may be slowing you down here.

  • How to obtain the running time of a task?

    How to obtain the running time of a task? I want to write a program about task progress.
    My email: [email protected]
    Thanks!

    First, Thanks for your code.
    But, I want obtain running time before running it.
    Example:
    class a extends JFrame{
    a() {
    initComponent() ;
    new progressBar(this); // my fancy. (may be other type variant.)
    void initComponent() {
    class progressBar {
    JProgressBar proBar = null ;
    Timer taskTime = null ;
    Double longTime = null ;
    progressBar(JFrame frame) { //JFrame or other.
    longTime = // ??????? You know ?????
    void monitor() {
    taskTime = new Timer(1000, new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    //repaint the proBar code.
    taskTime.start();
    }

  • How to set the expiry time of an image

    how to set the expiry time of an image from within the servlet or jsp

    I am sending an image with the page, so the set the page expiry in the browser cache we can use META tags of html or response.setDateHeader to set the Expires attribute, this setting the expiry time of the page but is not setting the expiry time of the image which is going with the page

  • [Urgent!!]How to control the running time??

    Hi,
    I'm an undergraduate researcher in the University of Michigan. I used NI labVIEW FPGA on my current project and now i meet a problem.
    I have a labview code that has runs with 3 subroutines. they execute one after another for a given time period for each iteration of the entire code. that is i built them in a flat sequence structure inside a large while loop and each of the subroutine is a while loop with several subvi's in it. not that complicated but i have to specify how long each subroutine runs. now i have a problem to set that execution time. i don't know exactly what kind of timing function i shall use. i tried the "Elapsed time" function but that only works for the first iteration. from the second iteration on each subroutine only runs for once, instead of continuing to run until the given time elapsed. so i don't know how to correctly control the running time. It's reallly urgent, so could you please give me some suggestions about it? Thanks a million!!
    Xiaofei

    Thank you for your suggestion!
    sorry but that this method won't help because my code is sort of difficult to put into a for loop .
    the logic is like this: first the output is set to 0 for a user-defined amount of time (means no excitation). secondly it gets excitation and gets output but no data saving is allowed for a user-defined amount of time. at the same time, one paramater is automatically changed. (the reason for not saving data is that there is a transient response when the parameter changes). thirdly, data saving begins with the same
    parameters as before, also for a user-defined amount of time. and then after these three steps one iteration is done. for iterations there is a different parameter, the user defines the range of the parameter and the number of different values in between and the code will do the increment at equal intervals automatically. my problem now is that i don't know how to correctly control the time. i have tried various ways but no one works.
    the second problem is that i don't know how to let it run and not saving data and then saving data without changing everything else. what i have now is to call the same VI twice, once for only running and no data saving and the other for saving data. but then the problem is that in between these two routines, the output suddenly becomes zero and gets excited again after i call it.  My professor said that i cannot let the output become zero, otherwise there is no meaning in waiting for the excitation to become stablee. but then i don't know how to call a VI only once and let it do the saving for only the latter part of the running time. i have been working on this thing for two weeks now and still have no idea....Sorry the problem is long and tedious, but if anyone have any idea about it, please let me know, i will be most grateful. Thanks a million!!!

  • Does anyone know how to set the starting time for an audio book?

    I am trying to restart a burn in iTunes that failed for an audiobook. I need to set the start time so it will not have to reburn the disks that were already completed. I cannot find out how to do that in version 11 if the book consists of more than one file. Anyone have an idea how to do this? Apple wants me to pay $20 for something that should be in the help menu.

    UCCX 5.0(2)SR02 is the version
    I attached a screenshot of what I am trying to use but I am not sure what to put as the value?  I tried using "now" and "null" but no success.

  • How to set the interval time in the   JFormattedTextField? Pls Contribute..

    Hi Frienz,
    Hi have a following code in which i want set the interval time for the TextField by 15 min
    So how it is possible please tell me out.
    DateFormatter frmtr = new DateFormatter();
                   SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                   frmtr.setFormat(sdf);
                   frmtr.setAllowsInvalid(false);
                   DefaultFormatterFactory factory = new DefaultFormatterFactory(frmtr, frmtr, frmtr);
                   fmtToTime.setFormatterFactory(factory);

    AFAIK there is no easy (pure java) way: either you exec something (depending on your paltform) or use native code. Appropriate privileges will be necessary.

  • I have a Canon Reble XTI, and would like to know how to set the self timer

    I have a Canon Reble XTI, and would like to know how to set the self timer

    If you don't have a copy of your manual, you'll want to download a copy.  You can get it from this page:  http://www.usa.canon.com/cusa/support/consumer/eos_slr_camera_systems/eos_digital_slr_cameras/digita...
    The instructions are on page 49 -- but really you should ready through the manual.  You'll learn a lot of capabilites of the camera that are worth knowing that you'd likely miss if you don't read it.
    There is a button on the back of your camera near the right edge of the LCD screen and it has an icon of a clock.  If you press that button, you can use the left/right arrows to enable the self-timer.
    It's a 10-second self-timer but it also puts the camera in a mode which allows it to be triggered via Canon's IR remote.  
    the current remote (which still works with your camera) is the Canon RC-6... it's not expensive -- just one button and it triggers the camera via IR.
    Tim Campbell
    5D II, 5D III, 60Da

  • How to get the running time on the page

    Hello ,
    I want to display the running clock and the user who loggin in .
    Pls let me know how to get the running clock display and the username who log in.
    thakns
    kumar

    Hi,
    You can use javascript clock and substitution string APP_USER
    Place this to HTML region source
    <input type="text" id="clock" /><span>&APP_USER.</span>
    <script language="JavaScript">
    function runClock(){
    theTime = window.setTimeout("runClock()", 1000);
    var RightNow = new Date();
    var hrNow = RightNow.getHours();
    var mnNow = RightNow.getMinutes();
    var scNow = RightNow.getSeconds();
    var miNow = RightNow.getTime();
    var mon = RightNow.getMonth() + 1;
    var date = RightNow.getDate();
    var year = RightNow.getFullYear();
    var day = RightNow.getDay();
    if(hrNow == 0) {hour = 12;var ap = " AM";}
    else if(hrNow <= 11) {ap = " AM";hour = hrNow;}
    else if(hrNow == 12) {ap = " PM";hour = 12;}
    else if (hrNow >= 13) {hour = (hrNow - 12);ap = " PM";}
    if(hrNow >= 13) {hour = hrNow - 12;}
    if(mnNow <= 9) {min = "0" + mnNow;}
    else{min = mnNow}
    if (scNow <= 9) {secs = "0" + scNow;}
    else {secs = scNow;}
    var zday=new Array(7)
    if (day==0) {zday="Sunday"};
    if (day==1) {zday="Monday"};
    if (day==2) {zday="Tuesday"};
    if (day==3) {zday="Wednesday"};
    if (day==4) {zday="Thursday"};
    if (day==5) {zday="Friday"};
    if (day==6) {zday="Saturday"};
    var zmon = new Array(12)
    if (mon==1) {zmon="January"};
    if (mon==2) {zmon="February"};
    if (mon==3) {zmon="March"};
    if (mon==4) {zmon="April"};
    if (mon==5) {zmon="May"};
    if (mon==6) {zmon="June"};
    if (mon==7) {zmon="July"};
    if (mon==8) {zmon="August"};
    if (mon==9) {zmon="September"};
    if (mon==10) {zmon="October"};
    if (mon==11) {zmon="November"};
    if (mon==12) {zmon="December"};
    $x('clock').value=""+zday+", "+zmon+" "+date+", "+year+" "+hour+":"+min+":"+secs+ap+"";
    runClock();
    </script>Use styles to get look you like to input and span tag
    Br,Jari

  • How to set the expiration time for a namedcache programmatically?

    I have a named cache with near cache configuration and no expiration specified in the cache-config. The backing map which is a distributed scheme has a size limited eviction policy but no expiration. I have an algorithm to determine the expiry delay of this named cache at run time. How can I set this delay programmatically on the named cache?
    Thanks
    Sairam

    Hi Sairam,
    You would need to get the backing map for the cache and then set the expiry on the backing map; assuming that the backing map supports expiry.
    For example:
    NamedCache cache = CacheFactory.getCache("test");
    CacheService service = cache.getCacheService();
    DefaultConfigurableCacheFactory.Manager bmm = (DefaultConfigurableCacheFactory.Manager) service.getBackingMapManager();
    Map bm = bmm.getBackingMap("test");
    if (bm instanceof ConfigurableCacheMap)
    System.out.println("Setting expiry delay");
    ((ConfigurableCacheMap) bm).setExpiryDelay(100000);
    -John

  • How to set the exposure time and the gain of a connected camera with IMAQ USB

    A camera was connected to my computer with USB port and we can acquire the image through IMAQ USB.  Now we have to set separately the exposure time and the gain with the camera's driver software provided by the manufacturer.  My question is: how to set directly the exposure time and the gain of this camera in Labview?

    Hi Frank
    Welcome to the forum. Have fun
    FranklinT wrote:
    My question is: how to set directly the exposure time and the gain of this camera in Labview?
    I think its not possible for USB Cameras. 
    Previous threads for your ref
    http://forums.ni.com/t5/Machine-Vision/How-to-control-property-nodes-for-USB-camera/td-p/970306
    http://forums.ni.com/t5/Machine-Vision/imaq-USB-property-page/td-p/926034
    Sasi.
    Certified LabVIEW Associate Developer
    If you can DREAM it, You can DO it - Walt Disney

  • How to know the run time of a program..?

    Hi Gurus,
    How to know the exact run time of a program....?
    Suppose i've a program....I've changed the code to improve the performance.
    Now i want to compare run time of older and new one...How to do this...?
    Pls help me ....
    Thanks and Regards,
    Nagarjuna

    Hi,
    go thru the below mentioned code............
    data:   start TYPE i,
              end TYPE i,
              dif TYPE i.
    GET RUN TIME FIELD start.
    SELECT SINGLE bukrs belnr gjahr blart budat
    FROM bkpf
    INTO (cc, doc, fy, doc_ty, pst_dt)
    WHERE bukrs = p_bukrs
    AND belnr = p_belnr
    AND gjahr = p_gjahr.
    GET RUN TIME FIELD end.
    dif = end - start.
    WRITE: /001 'Time for select',
    067 ':', dif, 'microseconds'.
    Reward all helpful answers.
    Thanks

  • How to set the correct time scale of VI ?

    I created a VI to display waveforms on the waveform graph. The problem is the time scale of the VI is always the year 1904.I tried to select absolute time in Property options of the waveform, but it remained the same. Can anybody help me with this? Thanks.

    > The x-scale is always 01/01/1904 even after I selected the 'absolute
    > time' option from waveform chart properties. If I add 2004 as offset
    > of x-scale as suggested by the previous post, the waveform of the
    > signal cannot be displayed, the system think it is still running in
    > 1904.Could you give me some further help?
    >
    Your description doesn't give enough information to pinpoint the
    problem, so I'll list off a few things that could be going on.
    The graphs and charts accept many datatypes. If you are using the
    waveform, display it on a regular waveform indicator and see what the
    timestamp and deltaT are. If these are correct, then the graph should
    be able to display things with no further changes except that you may
    need to turn on X Scale Autoscaling so that it will zoom and shift to
    show the plotted data. Charts will shift, but by default will not zoom
    in, and it might make sense there sometimes too depending on the delta T
    and amount of data plotted.
    If the timestamp on the waveform is incorrect, then it is much easier to
    construct the properly marked waveform than make the graph add to it to
    label the waveform's time differently.
    If you are not using the waveform, then you may be using a cluster of
    X0, dX, and Y array wired to the graph. This is very similar to the
    waveform, and again, it is better to add offsets to get the X0 to
    display correctly on a numeric. You can extract this number or display
    the cluster in an indicator, then format the numeric to display absolute
    time.
    If you are simply wiring the Y array, then LV will construct the X
    values based upon the number of points beginning at 0 and incrementing
    by one by default. When displayed as absolute time, this will default
    to midnight Jan 1 2004 plus an offset based upon your timezone. In this
    case, since there is no X information being piped into the graph, it is
    better corrected by going to the graph properties for the X Scale and
    setting the X Offset to the seconds between now and 1904. This is a
    constant you can compute when your program starts up or you can use a
    calculator, whichever is easier. You will also likely want to set the X
    Multiplier to the deltaT between successive points. 0.001 for 1KHz, 1
    for 1Hz, etc.
    Finally, if these suggestions don't make sense or don't help, you might
    want to explain more about what doesn't work.
    Greg McKaskle

  • How to set the system time in the program

    Hi All,
    How do we update the system time inside java programme.

    AFAIK there is no easy (pure java) way: either you exec something (depending on your paltform) or use native code. Appropriate privileges will be necessary.

Maybe you are looking for