Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Thread.currentThread().

    I saw a piece of codes like this in a Java class:

    Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);

    --My questions:

    1)Where could the Thread object be first created? I did a full application search (source codes) and did not find it. In another way, how could the Thread be directly used without first being instantiated?

    2)Where does it (getContextClassLoader().getResourceAsStream) try to get the filename?


    Thanks


    Scott

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Answers to your questions:

    1) Every application is inherently single threaded. Every time an application is kicked off it is running in it's own thread so the static call to Thread.currentThread() (assuming it's a single threaded application) will return your applications main thread. Beyond that, you can create separate threads within your program by creating your own instances of a Thread.

    2) Whatever the value of "filename" is, that's where the application is trying to load the file from. It should be defined within the code you're looking at, or passed in as a command line argument.

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Thanks for the response.

    The filename ="test.properties". But this file is located in the directory of C:\ibm\project_jars.

    I mean how could the system know this file (test.properties) is in the directoryof C:\ibm\project_jars ? Or where could the C:\ibm\project_jars be specified (I am using IBM's RAD 7)?


    Thanks

    Scott

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 2 Times in 2 Posts
    If the filename doesn't use an absolute path, it will look in the directory from which the application was launched. I believe this is stored in the system property "user.dir" but I could be wrong.

    If your application was launched from C:\ibm\project_jars then it should find the file. If not, then you'll have to do a little more digging.


  •  

    Posting Permissions

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