Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Multithreading / Asynchronous Using functional interfaces build an engine that retrieves useful addresses for endpoints. The API call should be on an asynchronous call, and printing the result should...

1 answer below »
Multithreading / Asynchronous
Using functional interfaces build an engine that retrieves useful addresses for endpoints.
The API call should be on an asynchronous call, and printing the result should be done as a callback.
Pseudocode:
while True:
      asyncGetAPI         
Read and parse the API
    thenPrintResult
Just print the parsed data
    Sleep 5 seconds
 
Example on how to read the API
URL address = new URL("https:
api.publicapis.org
andom (Links to an external site.)");
InputStreamReader reader = new InputStreamReader(address.openStream());
BufferedReader buffer = new BufferedReader(reader);
String contents = "";
String line = "";
while ((line = buffer.readLine()) != null) {
if (line.isEmpty()) {

eak;
}
contents += line;
}
API Address
https:
api.publicapis.org
andom
Answered 1 days After Jul 30, 2021

Solution

Kshitij answered on Aug 01 2021
154 Votes
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 01-Aug-21
* Time: 11:05 AM
* File: Sample.java
*
package August.aug01_21;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class Sample implements Runnable {
public static void main(String[] args) {
Sample ss = new Sample();
Thread t1 = new Thread(ss);
t1.start();
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here