Exp 2
Exp 2
ROLL NO : 21CO15
BATCH 03
PRACTICAL NO : 02
thread is also known as a lightweight process. The idea is to achieve parallelism by dividing a
process into multiple threads. For example, in a browser, multiple tabs can be different
threads. MS Word uses multiple threads: one thread to format the text, another thread to
process inputs, etc.
The primary difference is that threads within the same process run in a shared memory space,
while processes run in separate memory spaces.
Threads are not independent of one another like processes are, and as a result threads share
with other threads their code section, data section, and OS resources (like open files and
signals). But, like a process, a thread has its own program counter (PC), register set, and stack
space.
A multi-threaded program contains two or more parts that can run concurrently and each part
can handle a different task at the same time making optimal use of the available resources
especially when your computer has multiple CPUs.
Java code:
>Server.java import java.util.*; import java.io.*; import java.net.*; public class Server
{ public static void main(String args[]) throws Exception{
ss = MyServer.accept();
DataInputStream in;
DataOutputStream out; Socket socket; int sum; float res; boolean conn;
catch(Exception e){
System.out.println(e);
res = Integer.parseInt(input[1]) /
// String ip=(((InetSocketAddress)
this.socket.getRemoteSocketAddress()).getAddress()).toString().rep lace("/","");
this.out.flush();
catch(Exception E){
System.out.println(E);
} } closeConn();
catch(Exception E){
System.out.println(E);
}}
>Client.java
String send="",r="";
DataInputStream(MyClient.getInputStream());
DataOutputStream(MyClient.getOutputStream());
} dout.close(); din.close();
MyClient.close();
OUTPUT : Server.java
Client.java
Service:
Add+num num
Task: + 10 10
Answer: 20