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 »
See attachment.


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/random (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()) { break; } contents += line; } API Address https://api.publicapis.org/random
Answered 1 days AfterJul 30, 2021

Answer To: Multithreading / Asynchronous Using functional interfaces build an engine that retrieves useful...

Kshitij answered on Aug 01 2021
151 Votes
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 01-Aug-2
1
* 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