Best way to code a simple wait/delay?

What is the best way to code a simple wait/delay so that my application idles for a few seconds before continuing? I'd rather not use a loop to do this and am looking for a better solution. This code will not be threaded, so I'm not going to use sleep(). TIA

From the OS level, yes it is a process; from Java's perspective, it's a Thread, at least in Sun's implementation.
According to the JVM specification, section 2.1.9, "The Java virtual machine initially starts up with a single nondaemon thread, which typically calls the method main of some class. The virtual machine may also create other daemon threads for internal purposes. The Java virtual machine exits when all nondaemon threads have terminated."
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#33308

Similar Messages

  • Best way for a thread to wait without busy-waiting

    Hi!
    I have a thread that has nothing to do but to monitor the status of a variable
    public static boolean askToClose. This variable is set by other
    threads to indicate that this thread should stop now. But I don't want the thread
    to busy-wait like in this piece of code :
    public void run() {
         while (!askToClose) {
              Thread.sleep(1000);
         cleanAndStop();     
    }I'm new to Thread programming in Java so I'm not sure what's the best way to wait
    for an event without busy-waiting. I've tried using interruption instead of
    monitoring for the boolean variable :
    public void run() {
         try {
              synchronized (this) {
                   System.out.println("WAITING");
                   wait(0);
         catch (InterruptedException e) {
              System.out.println("INTERRUPTED !");
         cleanAndStop();     
    }and the other threads would simply call myThread.interrupt() instead of setting
    askToClose = true;And I've also used a LinkedBlockingQueue :
    public static LinkedBlockingQueue q = new LinkedBlockingQueue();
    public void run() {
         try {
              q.take();//Waiting
         catch (InterruptedException e) {}
         cleanAndStop();     
    }and on the other threads :
    MyThread.q.add(new Object());Which one is the best solution ? Do I really avoid busy waiting with this code? Is
    there a better way of doing this?
    Thx for your help !

    Your wait() based solution is OK, except that the other thread should
    use
    synchronized()
      notify();
    }

  • Best Way to Draw A Simple Isoceles Triangle, and Fill it.

    Hi,
    What I assume is a relativly simple problem, ive got the coordinates of the bottom two points of an isoceles triangle, and the height, and need to draw it in Java2D. It's base will always be parrellel to the bottom of the screen.
    I also need to be able to fill or not fill it very simple, what would be the best way to do this?
    Thanks for your time,
    atreides7887

    Create your triangle as an instance of [java.awt.Polygon|http://java.sun.com/javase/6/docs/api/java/awt/Polygon.html] and call [java.awt.Graphics2D.fill(Shape s)|http://java.sun.com/javase/6/docs/api/java/awt/Graphics2D.html#fill(java.awt.Shape)] to paint the triangle to a BufferedImage or in a paintComponent override.
    Read the other methods of Graphics2D for the rest of your answer.
    db

  • Best way to implement a simple read of multiple stings from a db

    Hello guys,
    I am trying to read a collection of countries (Strings) into a collection inside a Movie object. The countries reside in a separate DB table with a FK referencing the Movie.
    My questions:
    1) What is the best way to implement this? Do I need a seperate entity 'country' ? Is there a general way to read many strings into a collection?
    2) the countries list does not have to be updated, only read. How do I make sure it is not persistent?
    I have noticed that in my JPA implementation (in netbeans) I do not have something like CollectionOfElements (that is present in hybernate).
    Thank you,
    Marek

    >
    My questions:
    1) What is the best way to implement this? Do I need a seperate entity 'country' ? Is there a general way to read many strings into a collection?
    Probably yes, you need to have one entity for country.for getting the right answer, Post it here - Enterprise Technologies - Java EE SDK (http://forums.sun.com/forum.jspa?forumID=136)

  • Best way to do a simple Boolean test?

    Hello All,
      Trying to do a simple Boolean test, but it is proving to be more complicated than I would have expected.  Hoping that I am missing something simple.
    I have a Labview code module that provides a Boolean value for the output.  I want to evaluate this value and provide pass/fail results to the report.  Sounds simple, but here is what I am running into:
    -The built-in NI step type "Pass/Fail Test" will evaluate the Boolean directly with True=Pass, and False=Fail.  This would be fine, except that I have situations where I need False to equal Pass.  I've read a few posts that speak of inverting or negating the Boolean result, but they all involve passing the result to a parameter or variable, and then evaluating it outside of the test step.  This adds several layers that I don't think I should need.
    -I have read a post that suggested I convert the Boolean to a numeric inside of the code module.  This does indeed make sense, but this is not practical in my situation because of the scale and implementation of my code modules.  I use custom type definitions for controls and indicators from a Labview project, and would have to create a new control/indicator for every one if I wanted to change the data type.  
    -Next logical step was to see if the "Numeric Limit Test" would recognize a Boolean.  Turns out it doesn't.     
    -After this, I looked into creating a custom step type.  This would probably be the most useful, but it is beyond my current ability to do so.  I got as far as making a copy of the built in step type and putting it in the custom "MyTypes" directory, but I have made very little progress in editing it to make it a work.  Additionally, I've read a few posts that recommend avoiding custom step types.  
    Hoping someone can point me in the right direction.  Please advise.
    Thanks,
    GSinMN    
    Solved!
    Go to Solution.

    You could change the Data Source based on what value you want.  Since there doesn't appear to be an logical XOR, you will need to use a case statement.  For example, you could do:
    Locals.Desired? Step.Result.PassFail:!Step.Result.PassFail
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Best way to do a simple slide animation in GoLive 6?

    Hi,
    I'm an illustrator and manage my own site (only) in GoLive 6. I only update rarely and this last time it has been 3 years. My index page has a single image, but I'd like to use 4 or 5 images cycling in that spot with the best "disolve" I can get.
    www.daveseeley.com
    I've tried building the animation as a swf file in Imageready (cs2) = 10 second download of 3.4mb file in DSL=nonstarter...then tried an animated gif in which is about the same size, with much worse image quality, and it loads immediately and plays while continuing to load....so could work, but not ideal. I see that GoLive has a slideshow action, but cannot figure out how to do it.... Will that be with no dissolve setting=harsh transition if I just have the 4 or 5 images as jpegs with no transition files, or is there a way to do that automatically?
    I do have photoshop cs3, but haven't yet loaded it.
    Thanks for any help...
    Dave

    In article <[email protected]>,<br /> "David Seeley" <[email protected]> wrote:<br /><br />> Will that be with no dissolve setting=harsh transition if I just have the 4 <br />> or 5 images as jpegs with no transition files, or is there a way to do that <br />> automatically?<br /><br />Yes, GL's slide show action doesn't do transitions.<br /><br />I use a simple application called SWF'n Slide to create lean Flash <br />slideshows:<br /><a href=http://verticalmoon.com/products/swfnslide/swfnslidecommon.htm><br /><br />I have the Pro version, but the standard version offers loads of <br />features, too. Check out the samples:<br /><a href=http://verticalmoon.com/products/swfnslide/samples.php><br /><br />It's cheap and easy to figure out.<br /><br />-- <br />Cheers  Martin

  • What is the best way to design a simple form that is captured in structured accessible database/file?

    Hi there,
    I need to design a simple form to capture some data from the users. This data shall be able to post into structured database where I can connect to the content to grab the data automatically every night.
    What is the simple recommended way to do this?
    Thank you

    I will agree with Margriet Bruggeman, But if you want to have a collaboration with these data with security, then "Business Connectivity Services (BCS) " could be another option. It need more config/development but it has own use too.
    Few detail links
    A
    step by step guide in designing BCS entities by using a SQL stored procedure (Jyoti Saikia)
    Business Connectivity Services (BCS) Overview
    If SharePoint list form will be only data entry interface then go with InfoPath, if not then BCS
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Best way to code a Chat Application

    Hi
    I'm starting a project at work that is going to involve a chat mechanism between 2 parties only. Then the application will be needed to transfer a file, or maybe xml between the 2 clients.
    I'm looking into the various technologies to do this, so does anyone have any hint or ideas.
    Requirements are:
    work project
    run over internet, behind firewalls and proxies
    will only ever be a private chat between 2 parties
    must be able to share files/objects/xml
    secure
    fast reliable etc.
    I decided on an application rather than a website or applet. pointing towards sockets but not sure. also looking at SOAP.
    Any hints ?
    Thanks
    Stevie500

    Why dont you pull your head out?
    The idea (which you seem to have completely missed by an incredibly long way) is give something a go then ask for help. Are you honestly going to tell me you did a google search and thought "that looks like too much effort trying one of these examples, I'll be a troll and get someone to either write it for me or to choose one of the ideas for me cus I'm a bit thick".
    Is thinking "i'm going to write an app instead of an applet" as far as u got? omg.
    If you don't want to start from scratch my suggestion is to do a google search and try one of the examples.
    If you do want to start from scratch then learn about sockets. I wrote my first chat app in a couple of days. I knew java but nothing about sockets when i started. It dosn't take long (assuming you're not a lazy git).

  • What best way to create a simple DB based GUI application

    Hi
    I want to develop a small home-use DB GUI application. My questions relate to the GUI:
    1. If I want a main window to be a form containing mainly several text fileds (with labels attached) and a search button - what best layout manager would you reccomend?
    2. For good-practice programming I want to seperate my backend layer from the UI layer. Is there a good design pattern on how to do so?
    Thanks

    what best layout manager would you reccomend?Use a combination of Layout Managers to get the job done. See some example from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

  • Best Way to Make a Simple Java Program Configurable?

    I have a java program that does some stuff involving a database. It's basically a script, but I chose to use Java because of the nice JDBC facilities. Anyway, I plan to schedule a task to have the java program executed daily, but it would be nice if I could configure it without having to recompile the program every time. By configuration, I mean remembering about 6 lines of text, such as database connection address, user-name, password, spread sheet to update, etc. Since I am storing a username and password, I should also encrypt the data. Is there some standalone Java program that is made for creating config files, which would be encrypted and have some sort of an API to access all the data stored in the config file? I am basically thinking of a savable hashtable of Strings mapping keys to values where the values can be configured by some standalone application that allows the values associated with each key to be changed, preferably through a GUI. I could make this, but I figured there may already be something that does this.

    SNYP40A123 wrote:
    Only thing I still need is some way to hide the password that I plan to store in it.That's a completely separate issue. There could be a lot of discussion on this but basically you can't reliably hide a password that you store somewhere no matter what you do. You can do things that will prevent the idly curious from knowing it but it's a lot harder to prevent the determined cr&#97;cker from knowing it.

  • Best way to code to retrieve a field that matches one value

    Hello,
    Thanks for reading this post!
    I have a data set where users can be part of workgroups. I want to exclude any user that is part of workgroup 2 and 7, and only retrieve users that are solely part of workgroup 2.
    There can be users that are part of just workgroup 7 or other workgroups like 4, 5, 6 etc., but I only want users that have only workgroup 2 and no other workgroup.
    CREATE TABLE users
    ( user_id NUMBER(10)
    , user_lastname VARCHAR2 (50)
    , workgroup NUMBER(10)
    INSERT ALL
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (3, User_lastname3, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7)
    I want to exclude any users that have both workgroups 2 and 7 and
    only retrieve users that have just 2. In this case I only want to retrieve user_id 3.
    Thanks!
    Edited by: dbarcell on Oct 8, 2011 11:44 AM
    Edited by: dbarcell on Oct 8, 2011 11:48 AM
    Edited by: dbarcell on Oct 8, 2011 11:51 AM

    dbarcell wrote:
    Hello,
    Thanks for reading this post!
    I have a data set where users can be part of workgroups. I want to exclude any user that is part of workgroup 2 and 7, and only retrieve users that are solely part of workgroup 2.
    There can be users that are part of just workgroup 7 or other workgroups like 4, 5, 6 etc., but I only want users that have only workgroup 2 and no other workgroup.
    CREATE TABLE users
    ( user_id NUMBER(10)
    , user_lastname VARCHAR2 (50)
    , workgroup NUMBER(10)
    INSERT ALL
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (3, User_lastname3, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7)
    I want to exclude any users that have both workgroups 2 and 7 and
    only retrieve users that have just 2. In this case I only want to retrieve user_id 3.
    Thanks!
    Edited by: dbarcell on Oct 8, 2011 11:44 AM
    Edited by: dbarcell on Oct 8, 2011 11:48 AM
    Edited by: dbarcell on Oct 8, 2011 11:51 AMSQL> CREATE TABLE users
    ( user_id NUMBER(10)
    , user_lastname VARCHAR2 (50)
    , workgroup NUMBER(10)
    INSERT ALL
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (1, User_lastname1, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (2, User_lastname2, 7)
    INTO users(user_id, user_lastname, workgroup) VALUES (3, User_lastname3, 2)
    INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7) 2 3 4 5
    Table created.
    SQL> SQL> 2 3 4 5 6 7 ;
    INTO users(user_id, user_lastname, workgroup) VALUES (4, User_lastname4, 7)
    ERROR at line 7:
    ORA-00928: missing SELECT keyword
    test data is FUBAR!

  • What's the best way to do a simple click-to-enlarge photo?

    The slideshow and presentation widgets seem a bit elaborate for the purpose.

    Hello,
    Take a look at this post: http://forums.adobe.com/thread/1191086
    Cheers
    Parikshit

  • Best way to perform third party app integration in version 4.6

    I am working with a third-party vendor offering a freight and transportation rate software (Bourque Rateserver and Railtrac). 
    From our 4.6 system, we need to perform relatively simple remote SQL statements (inserts, call stored procs, reads).  We attempted to code these operations with EXEC SQL abap statements, but ran into permissions problems on the remote system.  We do not want to deploy middleware (XI, other EAI tools).  Can anyone provide thought on the best way to develop this simple integration?

    Hi Robert,
    We have a very similar requirement... to call a stored procedure on Borque RAILTRAC system to get the Rail Freight Rate at the time of creating a Sales Order. Can you please give me more details on how you have implemented the call to the stored procedure and how the RFC connection is established? Thanks a lot.

  • Best way to control and run multiple (up to 20) processes independantly in LV

    Hi all, 
    I'm trying to build an application in LV to independantly control and run multiple (up to 20) processes, ie, it should be able to start and stop any of the processes at any given time. What would the best way to code for this? Off the top of my head would be to use a unique notifier to control each of the process, but I'm thinking that the code upkeep may be a handful with this number of notifiers being defined. Are there better ways of doing this?
    Appreciate any help and insight on this.Thanks a bunch in advance!
    Solved!
    Go to Solution.

    I forgot some more important questions:
    How large is your development group?
    How much "discipline" do you want to program into the Process Commands framework? For instance, is it OK for any VI to command a process into a certain state, or should your program generate a broken wire or run-time error if a command is sent from a non-authorized source?
    Where do your needs fall on this spectrum: simplicity that gets the job done and the product out the door and will probably not need much maintenance or upgrading, or flexible framework that will likely undergo multiple upgrades or fall into the hands of multiple developers?
    a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}

  • Best way to implement this code in labview

    Hi
    What is the best way to implement this code in labview programming.
    I have an analogue input which triggers a boolean light when it reaches a certain voltage. but at the same time i would like it to enable two other outputs one for a set period of time and the other stay on until another statement becomes true.
    For example
    case 1:
    Set output high
    Delay(2000ms)
    Set output low
    Case 2:
    Set output high
    If statement 2 is true
    then set out put low
    if not then repeat until statement is true
    Thanks for your help

    Hi David,
    The code you posted will work, although note that the front panel becomes 'unresponsive' - as changes in the controls are only read once per iteration.  The wait function is an example of an execution timing VI, however if we want to do software timing (like a 2 hour wait) - we should use software timing VIs.
    Check out the following example (note we can stop execution during run-time):
    Regards,
    Peter D
    Attachments:
    SoftwareTiming.vi ‏26 KB

Maybe you are looking for