Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following scenario creates an console application that supports two threads. The application consists of three classes: Class1, Coffee, and Tea. Class1 contains the application’s main()method and code to start two threads — one to run the code for the Coffee class and one for the Tea class.
To create a multithreaded console application
On the File menu, click New Project to display the New Project dialog box.
Expand the folders for Visual J++ Projects and then Applications.
Single-click the Console Application icon.
In the Name text box, type a unique name for your project.
In the Location text box, enter or Browse to the location where you want to save your project.
In Project Explorer, expand your project’s icon and double-click on the Class1.java file.
Your .java file is now loaded in the and ready for modifications.
To add the Coffee and Tea classes to Class1.java file
At the end of the file, after
Class1’s closing brace, “{“, enter the code found in Coffee and Tea Source Code.Between the braces of Class1’s
main()method, insert the following code:Coffee m_Coffee = new Coffee(); //creates Coffee object m_Coffee.start(); //creates thread for Coffee object new Tea().start(); //creates Tea object and its thread