我们应该使用哪些用例ArrayIndexOutOfBoundsException
和`IndexOutOfBoundsException?
public class S3ButcketTest
{
public static void main(String args[])
{
System.setSecurityManager(new RMISecurityManager());
ForkJoinPool pool = new ForkJoinPool(1);
System.out.println("main: "+Policy.getPolicy());
pool.execute(new Runnable()
{
@Override
public void run()
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("pool: "+Policy.getPolicy());
}
});
pool.shutdown();
try
{
pool.awaitTermination(1000, TimeUnit.SECONDS);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用 VM 参数在两个不同的 JDK 版本(8 和 11)上运行:-Djava.security.policy=C:\test_system.policy
test_system.policy 内容:
grant {
permission java.security.AllPermission;
};
Run Code Online (Sandbox Code Playgroud)
使用JDK11运行时的输出:
main: sun.security.provider.PolicyFile@4cb2c100
Exception in thread "ForkJoinPool-1-worker-3" java.security.AccessControlException: access denied ("java.security.SecurityPermission" …
Run Code Online (Sandbox Code Playgroud) 我使用 spring Reactor 库编写了一个逻辑,以异步模式获取所有操作员,然后获取每个操作员的所有设备(分页)。
创建一个 Flux 来获取所有运算符,然后订阅它。
final Flux<List<OperatorDetails>> operatorDetailsFlux = reactiveResourceProvider.getOperators();
operatorDetailsFlux
.subscribe(operatorDetailsList -> {
for (final OperatorDetails operatorDetails : operatorDetailsList) {
getAndCacheDevicesForOperator(operatorDetails.getId());
}
});
Run Code Online (Sandbox Code Playgroud)
现在,对于每个运营商,我正在获取需要多个订阅才能获取设备 mono 的设备,该设备通过订阅 MONO 来异步获取所有页面。
private void getAndCacheDevicesForOperator(final int operatorId) {
Mono<DeviceListResponseEntity> deviceListResponseEntityMono = reactiveResourceProvider.getConnectedDeviceMonoWithRetryAndErrorSpec(
operatorId, 0);
deviceListResponseEntityMono.subscribe(deviceListResponseEntity -> {
final PaginatedResponseEntity PaginatedResponseEntity = deviceListResponseEntity.getData();
final long totalDevicesInOperator = PaginatedResponseEntity.getTotalCount();
int deviceCount = PaginatedResponseEntity.getCount();
while (deviceCount < totalDevicesInOperator) {
final Mono<DeviceListResponseEntity> deviceListResponseEntityPageMono = reactiveResourceProvider.getConnectedDeviceMonoWithRetryAndErrorSpec(
operatorId, deviceCount);
deviceListResponseEntityPageMono.subscribe(deviceListResponseEntityPage -> {
final List<DeviceDetails> deviceDetailsList = deviceListResponseEntityPage.getData() …
Run Code Online (Sandbox Code Playgroud) 就像我有这两个场景我们必须处理FileNotFoundException
情况1:
try {
FileInputStream fis = new FileInputStream("test1.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
案例2:
try {
FileInputStream fis = new FileInputStream("test1.txt");
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
在两种情况下,打印的Stack Trace都是相同的.我想知道两种实现之间的区别以及应该首选的内容?
我有一个正则表达式/ \ s *,\ s * /,它匹配左空格,然后是逗号,然后是右空格。
例:
var str = "john,walker james , paul";
var arr = str.split(/\s*,\s*/);
Values in arr = [john,walker james,paul] // Size: 3
Run Code Online (Sandbox Code Playgroud)
带有汉字的示例:
var str = "????? ?? ???";
var arr = str.split(/\s*,\s*/);
Values in arr = ["????? ?? ???"] // Size: 1, All values at index 0 no splitting happened
Run Code Online (Sandbox Code Playgroud)
尝试使用Unicode分割字符:
var str = "john,walker james , paul";
var arr = str.split(/\u0020*\u002C\u0020*/);
Values in arr = [john,walker james,paul] // Size: 3 …
Run Code Online (Sandbox Code Playgroud)