Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How can I make this multithreaded?

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default How can I make this multithreaded?

    Multithreading means I can run two methods at once right? If so, how can I apply multithreading to this code snippet?

    if(playedSong.get_name_of_song().contains(sd)) //1st
    {
    SkrillexDamian.play();
    }

    countDown(convertTime(input)); //2nd


    Thank you sincerely,
    littlepresman

    --- Update ---

    If I am totally wrong in assuming multithreading will help me in accomplishing my goal of running the countDown and playedSong at the same time, what will? Any help is much appreciated, and if you need to see more of my code just let me know.

    Thanks again,
    littlepresman


  2. #2
    Junior Member
    Join Date
    Jun 2014
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How can I make this multithreaded?

    Hello!

    I do not really understand your question.

    Each new thread may be started as follows:


    Thread mythread = new Thread() {
           public void run() {
                 //YOUR CODE TO EXECUTE GOES HERE
           }
    }
     
    mythread.start();

  3. The Following User Says Thank You to aigarzs For This Useful Post:

    littlepresman (June 22nd, 2014)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,316
    My Mood
    Mellow
    Thanks
    194
    Thanked 671 Times in 658 Posts

    Default Re: How can I make this multithreaded?

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post you code correctly per the above link.

    The example you gave is too minimal. A counter and a another task could easily be run in separate threads, but what might be more important to your project is how the result of each thread is used by the other, and you haven't given us the details necessary to understand that.

  5. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How can I make this multithreaded?

    I've created a new post as per request of the moderators, in it includes my code (formatted) and a clearer questions.

    Thanks again!

    How can I run two methods at the same time?

  6. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,316
    My Mood
    Mellow
    Thanks
    194
    Thanked 671 Times in 658 Posts

    Default Re: How can I make this multithreaded?

    Nobody requested you start another thread. Next time, just add to the existing thread in order to answer the questions asked and clarify the original post.

    Thread closed.

Similar Threads

  1. Multithreaded client/server
    By keepStriving in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 12th, 2013, 05:47 PM
  2. MultiThreaded Scheduler
    By sci4me in forum Java Theory & Questions
    Replies: 3
    Last Post: April 21st, 2013, 06:26 PM
  3. Multithreaded Proxy Server java
    By hivesh in forum What's Wrong With My Code?
    Replies: 13
    Last Post: February 2nd, 2013, 11:19 AM
  4. Java is Multithreaded
    By Bijaysadhok in forum Java Theory & Questions
    Replies: 1
    Last Post: February 23rd, 2012, 06:17 AM
  5. Replies: 0
    Last Post: January 22nd, 2011, 10:52 AM

Tags for this Thread