Rewrite this code using implements Callable Note:(In Java Language) package cheeg; import java.io.*; import

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Rewrite this code using implements Callable Note:(In Java Language) package cheeg; import java.io.*; import

Post by answerhappygod »

Rewrite this code using implements Callable
Note:(In Java Language)
package cheeg;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
class WorkingThread extends Thread{
private String name;
public WorkingThread(String name){
this.name=name;
}
public void run(){
try{
InetAddress
add[]=InetAddress.getAllByName(name);

for(InetAddress a:add)

System.out.println(name +" ip
address"+a.getHostAddress());
}catch(Exception e){

e.printStackTrace();
}
}
}
public class Cheeg {
public static void main(String[] args) throws
Exception{
BufferedReader bufr=new
BufferedReader(new FileReader("c:\\threads\\homework.txt"));
String Line;
ArrayList<WorkingThread> str=new
ArrayList<WorkingThread>();

while((Line=bufr.readLine())!=null)
str.add(new
WorkingThread(Line));
for(int i=0;i<str.size();i++)
str.get(i).start();
}

}
the Output Should be Like this:
Rewrite This Code Using Implements Callable Note In Java Language Package Cheeg Import Java Io Import 1
Rewrite This Code Using Implements Callable Note In Java Language Package Cheeg Import Java Io Import 1 (7.67 KiB) Viewed 15 times
txt file should have:
Rewrite This Code Using Implements Callable Note In Java Language Package Cheeg Import Java Io Import 2
Rewrite This Code Using Implements Callable Note In Java Language Package Cheeg Import Java Io Import 2 (10.41 KiB) Viewed 15 times
Output - cheeg (run) run: ▷▷ www.google.com ip address142.250.186.36 www.w3schools.com ip address192.229.133.221 www.op.gg ip address 65.9.110.101 www.op.gg ip address 65.9.110.120 www.op.gg ip address 65.9.110.13 www.op.gg ip address 65.9.110.43 BUILD SUCCESSFUL (total time: 1 second)
homework - Notepad File Edit Format View Help www.w3schools.com www.op.gg www.google.com Ln 1, Col 1 100% Windows (CRLF) | X UTF-8
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply