So looking over the lessons on Threads, and trying to implement it here, I realized I didn't understand something.
When we start the thread in the main method we may have something like
new ReadThread(string).start();
then in the RunThread method we create something like
Private String fileName;
Later we continue to use the fileName string in the FileInputStream.
My question is, how is the actual file name (string) turn into "fileName" in the RunThread method.
Perhaps this is a basic question, but I don't see it?
Thanks
Passing filename to thread
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
19 August 2021, 07:24useful
Hi Ryan, when you crate a ReadThread you're passing the fileName to the objects constructor
Inside the constructor the usual happens, storing the passed argument in a (private) String field fileName. Now any object of the type ReadThread has its own fileName (field) and can use it. +1
Ryan Palmer
20 August 2021, 01:40
Thank you Thomas, got it! That was my guess, but I didn't understand the steps. Thanks for clarifying.
0