我有以下方法:
public String getResult() {
List<String> serversList = getServerListFromDB();
List<String> appList = getAppListFromDB();
List<String> userList = getUserFromDB();
return getResult(serversList, appList, userList);
}
Run Code Online (Sandbox Code Playgroud)
在这里,我按顺序调用三个方法,然后点击DB并获取结果,然后我对从DB命中获得的结果进行后处理.我知道如何通过使用同时调用这三种方法Threads.但我想用Java 8 Parallel Stream来实现这一目标.有人可以指导我如何通过Parallel Streams实现同样的目标吗?
编辑我只想通过Stream并行调用方法.
private void getInformation() {
method1();
method2();
method3();
method4();
method5();
}
Run Code Online (Sandbox Code Playgroud) 我需要一个Collection对元素进行排序,但不会删除重复项.
我已经去了TreeSet,因为TreeSet实际上将值添加到支持TreeMap:
public boolean add(E e) {
return m.put(e, PRESENT)==null;
}
Run Code Online (Sandbox Code Playgroud)
TreeMap使用Comparators compare逻辑删除重复项
我写了一个Comparator在相同元素的情况下返回1而不是0.因此,在相同元素的情况下,TreeSet使用它Comparator不会覆盖副本,只会对其进行排序.
我已经测试了它的简单String对象,但我需要一组自定义对象.
public static void main(String[] args)
{
List<String> strList = Arrays.asList( new String[]{"d","b","c","z","s","b","d","a"} );
Set<String> strSet = new TreeSet<String>(new StringComparator());
strSet.addAll(strList);
System.out.println(strSet);
}
class StringComparator implements Comparator<String>
{
@Override
public int compare(String s1, String s2)
{
if(s1.compareTo(s2) == 0){
return 1;
}
else{
return s1.compareTo(s2);
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 java 8将 Date 转换为GMT +5:30to 。ESTZonedDateTime
String inputDate = "2015/04/30 13:00";
DateTimeFormatter sourceFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm", Locale.US);
LocalDateTime local = LocalDateTime.parse(inputDate, sourceFormatter);
// local : 2015-04-30T13:00
//Combining this local date-time with a time-zone to create a ZonedDateTime.
ZonedDateTime zoned = local.atZone(TimeZone.getTimeZone("GMT+5:30").toZoneId());
// zoned : 2015-04-30T13:00+05:30[GMT+05:30]
ZonedDateTime zonedUS = zoned.withZoneSameInstant(TimeZone.getTimeZone("GMT-5:00").toZoneId());
// zonedUS : 2015-04-30T02:30-05:00[GMT-05:00]
Run Code Online (Sandbox Code Playgroud)
我期待3:30 AM EST,但是我所得到的是2:30 AM EST作为1 PM IST= 3:30AM EST。我错过了什么?
在Audience Network Android SDK中,我们使用127.0.0.1(localhost)作为缓存代理来缓存SDK中的媒体文件.自Android P起,默认情况下将禁止明文流量(未加密的HTTP),这将影响SDK的媒体缓存功能,并可能影响用户体验和广告收入.
现在,如果我尝试android:networkSecurityConfig="@xml/network_security_config"在我的行中添加此行,我会AndroidManifest收到警告,因为我的应用程序支持minSdkVersion 15,因此在API 24及更高版本中使用属性networkSecurityConfig .
我应该如何添加android:networkSecurityConfig它,以便它不会影响小于24的API
在这里,我使用Javaparallel流来迭代List并使用每个列表元素作为输入调用REST调用.我需要将REST调用的所有结果添加到我正在使用的集合中ArrayList.下面给出的代码工作正常,只是ArrayList的非线程安全性会导致错误的结果,并且添加所需的同步会导致争用,从而破坏并行性的好处.
有人可以建议我在我的案例中使用并行流的正确方法.
public void myMethod() {
List<List<String>> partitions = getInputData();
final List<String> allResult = new ArrayList<String>();
partitions.parallelStream().forEach(serverList -> callRestAPI(serverList, allResult);
}
private void callRestAPI(List<String> serverList, List<String> allResult) {
List<String> result = //Do a REST call.
allResult.addAll(result);
}
Run Code Online (Sandbox Code Playgroud) 我有一个input框,其中有onBlur用于验证的功能。
我面临的问题是,当我直接单击“提交”按钮而不从
input框中跳出时,在onBlur函数调用之前就已经提交了表单,并且验证没有发生。
有人可以在这里建议解决方法。我在JSP页面中使用javascript和JQuery。
我收到错误:
Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of com.zee.FilterVO out of START_ARRAY token. at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1b54362; line: 1, column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: : Can not deserialize instance of com.zee.FilterVO out of START_ARRAY token
Java调用获取JSON:
ResponseEntity<FilterVO> responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, FilterVO.class);
Run Code Online (Sandbox Code Playgroud)
用于映射JSON的Java Bean:
public class FilterVO {
private String userName;
private String expirationTime;
private String lastMatchedTime;
private String state;
private Integer matchedTodayCount;
private Boolean useRegEx;
private List<String> matchStrings;
private List<String> hosts; …Run Code Online (Sandbox Code Playgroud) 当我尝试在 Kibana 中创建索引模式时,我的 elasticserach 集群出现故障。没有猫 API 正在工作,例如。_猫/节点
在弹性主节点日志中,我可以看到:
Caused by: org.elasticsearch.transport.ReceiveTimeoutTransportException: [data-3-vm-zone-1227643n][xx.xx.133.151:9300][cluster:monitor/nodes/stats[n]] request_id [9651533] timed out after [15000ms]
at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:908) ~[elasticsearch-5.2.0.jar:5.2.0]
... 4 more
[2017-02-15T06:38:40,046][ERROR][o.e.x.m.c.i.IndexRecoveryCollector] [master1-vm-zone-p1227651n] collector [index-recovery-collector] timed out when collecting data
[2017-02-15T06:38:50,047][ERROR][o.e.x.m.c.i.IndexStatsCollector] [master1-vm-zone-p1227651n] collector [index-stats-collector] timed out when collecting data
[2017-02-15T06:39:00,048][ERROR][o.e.x.m.c.i.IndicesStatsCollector] [master1-vm-zone-p1227651n] collector [indices-stats-collector] timed out when collecting data
[2017-02-15T06:39:10,048][ERROR][o.e.x.m.c.c.ClusterStatsCollector] [master1-vm-zone-p1227651n] collector [cluster-stats-collector] timed out when collecting data
[2017-02-15T06:39:30,152][ERROR][o.e.x.m.c.i.IndexRecoveryCollector] [master1-vm-zone-p1227651n] collector [index-recovery-collector] timed out when collecting data
[2017-02-15T06:39:31,884][DEBUG][o.e.a.a.c.n.s.TransportNodesStatsAction] [master1-vm-zone-p1227651n] failed to execute on node [FN8JwM_rS7WgSP0h9hXvMA]
org.elasticsearch.transport.ReceiveTimeoutTransportException: [data-3-vm-zone-p1227643n][xx.xx.133.151:9300][cluster:monitor/nodes/stats[n]] request_id …Run Code Online (Sandbox Code Playgroud) 当我尝试安装 Burrow https://github.com/linkedin/Burrow#build-and-install时
go get github.com/linkedin/Burrow
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
package gopkg.in/gcfg.v1: unrecognized import path "gopkg.in/gcfg.v1"
(https fetch: Get https://gopkg.in/gcfg.v1?go-get=1: proxyconnect tcp: dial tcp :0: getsockopt: connection refused)
Run Code Online (Sandbox Code Playgroud)
我已经通过以下方式设置了代理:
export http_proxy=myproxy:port
export https_proxy=myproxy:port
Run Code Online (Sandbox Code Playgroud)
编辑:
go get -u gopkg.in/gcfg.v1
Run Code Online (Sandbox Code Playgroud)
也给出了同样的错误:
package gopkg.in/gcfg.v1: unrecognized import path "gopkg.in/gcfg.v1"
(https fetch: Get https://gopkg.in/gcfg.v1?go-get=1: proxyconnect tcp: dial tcp :0: getsockopt: connection refused)
Run Code Online (Sandbox Code Playgroud)
编辑1:
go get -v gopkg.in/gcfg.v1
Fetching https://gopkg.in/gcfg.v1?go-get=1
https fetch failed: Get https://gopkg.in/gcfg.v1?go-get=1: proxyconnect tcp: dial tcp :0: getsockopt: connection refused
package gopkg.in/gcfg.v1: unrecognized import path …Run Code Online (Sandbox Code Playgroud) 在这里,我有以下代码:
int a,b,x;
a=b=1;
x=a+++b;
Run Code Online (Sandbox Code Playgroud)
现在,值x将是2,因为a第一个是后递增,然后它被添加到b.
以下是编译的字节代码:
0 iconst_1
1 dup
2 istore_2 [b]
3 istore_1 [a]
4 iload_1 [a]
5 iinc 1 1 [a]
8 iload_2 [b]
9 iadd
10 istore_3 [x]
Run Code Online (Sandbox Code Playgroud)
所以表达式将等同于x = (a++) + b.
现在另一个表达式x=a++++b,因为最大的munch规则而不会编译.它将成为x = (a++) ++ b编译错误.
上述行为是x=a+++b因为运算符 ++ 的优先级还是因为最大的munch规则?
java ×6
java-8 ×2
android ×1
collections ×1
concurrency ×1
forms ×1
go ×1
html ×1
http-proxy ×1
jackson ×1
java-stream ×1
javascript ×1
jquery ×1
json ×1
jsp ×1
resttemplate ×1
spring ×1
timezone ×1
treemap ×1
treeset ×1