IT 351 Colorado Technical University Multi Threaded Server Applications Questions

Primary Task Response:Within the Discussion Board area, write 400–600 words that respond to the following questions with your thoughts, ideas, and comments. This will be the foundation for future discussions by your classmates. Be substantive and clear, and use examples to reinforce your ideas:

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Explain how you would modify your server to make it multithreaded, allowing more than one client to connect and request product and customer data.

  • Be sure you specifically identify which Java API classes you intend to use.
  • Responses to Other Students: Respond to at least 2 of your fellow classmates with at least a 100-word reply about their Primary Task Response regarding items you found to be compelling and enlightening. To help you with your discussion, please consider the following questions:

  • What did you learn from your classmate’s posting?
  • What additional questions do you have after reading the posting?
  • What clarification do you need regarding the posting?
  • What differences or similarities do you see between your posting and other classmates’ postings?
  • 1st peer to respond 2

    Discussion Board Unit 2

    Save Time On Research and Writing
    Hire a Pro to Write You a 100% Plagiarism-Free Paper.
    Get My Paper
  • Explain how you would modify your server to make it multithreaded, allowing more than one client to connect and request product and customer data.
  • Be sure you specifically identify which Java API classes you intend to use.

    Java supports single-thread and multi-thread operations. A single-thread program has one entry point and a single exit point. A multi-thread program has an initial entry point followed by many entry and exit points. The term “concurrency” refers to doing more than one task at the same time.

    Java has support for concurrent programming and can run more than one thread at the same time within a single program. A threadin programming is one sequential flow operation, with a definite beginning and an end. During the lifetime of the thread, there is only one point of execution. A thread by itself is not a program because it cannot run on its own. Instead, it runs inside the program.

    There are a couple ways to create thread in java, one is to implement the Runnable interface (java.lang.Runnable), the other is by Extending the Thread class (java.lang.Thread). In this program I think I will use the java.lang.Runnable import.

    References

    Multithreaded socket programming in Java? (n.d.). Retrieved February 27, 2021, from

    http://net-informations.com/java/net/multithreaded.htm

    Programming assignment 1: Building a multi-threaded web server. (n.d.). Retrieved February 27, 2021, from

    https://www2.seas.gwu.edu/~cheng/6431/Projects/Project1WebServer/webserver.html

    the final peer to respond to

    According to my research, Java programming is a very versatile programming language and can be used to create powerful servers. A single server or a single client connection can be created by using Java socket APIs. For my project, I will multi-thread using the java.lang.Runnable interface to allow more than one client to connect and request product and customer data. multi-threading defines the capability of a software, an operating system, or a hardware component to manage more than one user at a time. A multi-threaded application can accept multiple requests by one user or many users without running multiple instances of the program on the computer. Each thread has a special identity so that the application can easily keep track of the commands given to it. Multi-threaded applications keep a track of the requests and the status of work assigned to each thread.

    While researching, I found the following example:a desktop application providing functionality like editing, printing, etc. is a multithreaded application. The threads in multithreaded applications run parallel to each other in a concurrent manner. Multithreading is also a part of concurrency in Java. Multithreading is useful as it provides concurrent execution of two or more parts of an application. Below are some of the terms relating to multi-threading that I have begun to familiarize myself with:

    Multitasking: more than one task is executed at the same time.

    Multithreading: is a process of executing multiple threads simultaneously.

    Multiprocessing: more than one process is executed simultaneously. Similar to multitasking, but more than one CPU is involved.

    Parallel Processing: Parallel processing is a technique where multiple CPUs work simultaneously in a computer system.

    Below are also examples of client and server codes that can be used in multi-threading

    import java.net.ServerSocket;

    import java.net.Socket;

    import java.io.IOException;

    public class ServerMultithreaded implements Runnable{

    protected int serverPortVal = 8080;

    protected ServerSocket serverSocketVal = null;

    protected boolean hasStopped = false;

    protected Thread movingThread= null;

    public ServerMultithreaded(int port){

    this.serverPortVal = port;

    }

    public void run(){

    synchronized(this){

    this.movingThread = Thread.currentThread();

    }

    opnSvrSocket();

    while(! hasStopped()){

    Socket clntSocket = null;

    try {

    clntSocket = this.serverSocketVal.accept();

    } catch (IOException e) {

    if(hasStopped()) {

    System.out.println(“Server has Stopped…Please check”) ;

    return;

    }

    throw new RuntimeException(

    “Client cannot be connected – Error”, e);

    }

    new Thread(

    new WrkrRunnable(

    clntSocket, “This is a multithreaded Server”)

    ).start();

    }System.out.println(“Server has Stopped…Please check”) ;}

    private synchronized boolean hasStopped() {

    return this.hasStopped;

    }

    public synchronized void stop(){

    this.hasStopped = true;

    try {

    this.serverSocketVal.close();

    } catch (IOException e) {

    throw new RuntimeException(“Server can not be closed – Please check error”, e);

    }}

    private void opnSvrSocket() {

    try {

    this.serverSocketVal = new serverSocketVal(this.serverPortVal);

    References:

    Multi-threading in Java. (2021, February 18). Retrieved from:

    Multithreading In Java – Tutorial With Examples (softwaretestinghelp.com)

    Learn How to Create a Multi-threaded Server in Java. (2016, May 12). Retrieved from:

    Learn How to create a multi-threaded Server in Java? (eduonix.com)

    } catch (IOException e) {

    throw new RuntimeException(“Not able to open the port 8080”, e);

    }}}

    Public class Client{

    publics static void main(String [] agrs) throws IOException{

    ServerMultithreaded newServer = new ServerMultithreaded(9191);

    new Thread(newServer).start();

    try {

    Thread.sleep(15 * 1000);

    } catch (InterruptedException e) {

    e.printStackTrace();

    }

    System.out.println(“Stopping newServer”);

    newServer.stop();

    Still stressed from student homework?
    Get quality assistance from academic writers!

    Order your essay today and save 25% with the discount code LAVENDER