What Is Meant By Threads In Java ? How Do You Create A Network Server Application In Java?
Can't find what you're looking for?
Ask a Question, Get an Answer ASAP
The thread is a small process and in Java, user can create threads in several ways. The simplest way of programming with thread in java is to take an existing class and mold it into a thread program. A good programmer do this by modifying the class so that it implements the Runnable interface, which declares the run () method.
The run () method is required by all types of threads. The run () method restrict the code to be executed by a thread. The second way to create a thread is to write a completely separate class inherited from Java's Thread class. Because the Thread class itself implements the Runnable interface, it already restrict a run () method. The thread programming is mostly work with java network classes. In client/server model, there is one server program that supports multiple clients; it is a perfect application for threads.
A server program has one main thread that manages the listening socket. Whenever the server socket receives a connection request from a client, the main thread makes a new thread to maintain the communications with that exceptional client. This client thread will run only as long as the client connected to the server. A server that works in this way as client, then it is known as multithreaded envoirment.
answered 2 years ago
Ask questions on any topic, get great answers from real people for FREE. Blurtit has hundreds of thousand of members so your sure to get the answer your looking for.