Review changes
This commit is contained in:
parent
8f01547516
commit
b907d2cd6e
@ -1,6 +1,14 @@
|
|||||||
package com.baeldung.jcabi;
|
package com.baeldung.jcabi;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -9,7 +17,6 @@ import com.jcabi.aspects.Async;
|
|||||||
import com.jcabi.aspects.Cacheable;
|
import com.jcabi.aspects.Cacheable;
|
||||||
import com.jcabi.aspects.LogExceptions;
|
import com.jcabi.aspects.LogExceptions;
|
||||||
import com.jcabi.aspects.Loggable;
|
import com.jcabi.aspects.Loggable;
|
||||||
import com.jcabi.aspects.Parallel;
|
|
||||||
import com.jcabi.aspects.Quietly;
|
import com.jcabi.aspects.Quietly;
|
||||||
import com.jcabi.aspects.RetryOnFailure;
|
import com.jcabi.aspects.RetryOnFailure;
|
||||||
import com.jcabi.aspects.UnitedThrow;
|
import com.jcabi.aspects.UnitedThrow;
|
||||||
@ -21,9 +28,9 @@ public class JcabiAspectJ {
|
|||||||
displayFactorial(10);
|
displayFactorial(10);
|
||||||
getFactorial(10).get();
|
getFactorial(10).get();
|
||||||
|
|
||||||
Double number = cacheRandomNumber();
|
String result = cacheExchangeRates();
|
||||||
if (number != cacheRandomNumber()) {
|
if (result != cacheExchangeRates()) {
|
||||||
System.out.println(number);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
divideByZero();
|
divideByZero();
|
||||||
@ -32,7 +39,12 @@ public class JcabiAspectJ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
divideByZeroQuietly();
|
divideByZeroQuietly();
|
||||||
parallelExecution();
|
try {
|
||||||
|
processFile();
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Loggable
|
@Loggable
|
||||||
@ -64,11 +76,19 @@ public class JcabiAspectJ {
|
|||||||
|
|
||||||
@Loggable
|
@Loggable
|
||||||
@Cacheable(lifetime = 2, unit = TimeUnit.SECONDS)
|
@Cacheable(lifetime = 2, unit = TimeUnit.SECONDS)
|
||||||
public static Double cacheRandomNumber() {
|
public static String cacheExchangeRates() {
|
||||||
return Math.random();
|
String result = null;
|
||||||
|
try {
|
||||||
|
URL exchangeRateUrl = new URL("https://api.exchangeratesapi.io/latest");
|
||||||
|
URLConnection con = exchangeRateUrl.openConnection();
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
result = in.readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UnitedThrow(IllegalStateException.class)
|
|
||||||
@LogExceptions
|
@LogExceptions
|
||||||
public static void divideByZero() {
|
public static void divideByZero() {
|
||||||
int x = 1/0;
|
int x = 1/0;
|
||||||
@ -80,9 +100,13 @@ public class JcabiAspectJ {
|
|||||||
int x = 1/0;
|
int x = 1/0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parallel(threads = 4)
|
@UnitedThrow(IllegalStateException.class)
|
||||||
public static void parallelExecution() {
|
public static void processFile() throws IOException, InterruptedException {
|
||||||
System.out.println("Calling Parallel...");
|
BufferedReader reader = new BufferedReader(new FileReader("baeldung.txt"));
|
||||||
|
reader.readLine();
|
||||||
|
|
||||||
|
Thread thread = new Thread();
|
||||||
|
thread.wait(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user