×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    Java app - holding a thread ?

    A general question;
    What is the recommendation - if a J2ME app playing an audio <player.start ()>, should the app need to wait till the track finishes.

    For ex.
    while (playerPlaying) { // playerPlaying is boolean, set to false at End-Of-Media
    Thread.sleep (1);
    }

    Or is it not a good practice to "hold" the thread ???

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Java app - holding a thread ?

    I think that you should play the sound file inside thread only and only if the player started request was from the Event Handler like the commandAction() or the keyPressed() etc. Else you are not required to play the same file on the thread.

    Why are you planning to run the same file on the thread?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Java app - holding a thread ?

    don't hold the thread.
    instead, give your player a PlayerListener ( http://java.sun.com/javame/reference...rListener.html ) which will notify you when the track is finished.

    it is generally not a very good practice to hold a thread, but there are exceptions where it is perfectly justified.
    the correct method is to use the wait/notify mechanism :
    in Thread 1 run() :

    synchronised (this) {
    wait();
    }

    Anywhere, when the thread 1 should continue :
    synchronized (thread1) {
    thread1.notify();
    }

    use with caution. the use of synchronized blocks can lead to deadlocks and other unexpected behaviours.

Similar Threads

  1. Holding multiple bitmaps in memory
    By sbail in forum Symbian Media (Closed)
    Replies: 5
    Last Post: 2009-08-12, 09:25
  2. Java App Midlet certification (new thread)
    By mocad_tom in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2008-06-24, 04:12
  3. Replies: 2
    Last Post: 2006-04-04, 19:26
  4. Holding storage-3310
    By cancer10777 in forum Smart Messaging
    Replies: 0
    Last Post: 2005-08-15, 21:03
  5. Installing Java App over Bluetooth, from inside a Java App or a PC Access Point
    By a_n_k_u_r in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2005-07-30, 18:05

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×