Results 1 to 3 of 3

Thread: Threads

  1. #1
    Join Date
    Oct 2012
    Location
    San Saba Tx.
    Posts
    8
    Rep Power
    0

    Default Threads

    Forgive me if im doing this wrong my first time using a forum.
    Ok my question is if i create a method in a seperate class file from the one with the main method to create a new thread can i make a way that when i call it in my main method that i just enter what i want it to do in a String or something and it creates the thread and does whats in the String!
    Thanks in advance!!!

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Threads

    No, not in pure java. That is dynamic behavior and would require some kind of dynamic code evaluation. The Groovy language (java based) supports exactly this. You can write any arbitrary code in a text file, open the file with your app, and execute the code in the file, all at runtime. To do this in java, you need to use a rather complex combination of interfaces and a domain specific language you make up yourself. Java is not the best language for doing this kind of thing (it's a lot of work) but it can be (and has been) done.

    If you're a fan of java, need to use the JVM, but also really need dynamic behavior, take a look at groovy. It'll work with your existing java code, but has a lot of other cool tricks too!

  3. #3
    Join Date
    Oct 2012
    Location
    San Saba Tx.
    Posts
    8
    Rep Power
    0

    Default Re: Threads

    Thank you for the help and i will look into groovy!

Similar Threads

  1. threads
    By kyle_maddisson in forum New To Java
    Replies: 1
    Last Post: 12-10-2011, 04:12 AM
  2. New to threads
    By armyson in forum Threads and Synchronization
    Replies: 0
    Last Post: 12-09-2011, 08:52 AM
  3. Threads per Connection or Threads per Request
    By Felic in forum New To Java
    Replies: 4
    Last Post: 11-22-2011, 10:15 PM
  4. threads
    By brindha1688 in forum New To Java
    Replies: 3
    Last Post: 05-24-2011, 09:07 PM
  5. Using threads
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 11:25 AM

Tags for this Thread

Posting Permissions

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