小编msa*_*yag的帖子

Map.of()与Collections.emptyMap()

Map.of()Collections.emptyMap()之间List.of(),Collections.emptyList()和之间Set.of()和之间是否存在差异Collections.emptySet()

java collections java-9

17
推荐指数
1
解决办法
1199
查看次数

服务泄露了最初绑定在这里的ServiceConnection

我正在使用启动IntentService的BraodCastReceiver.Everythings看起来很好用,但是我得到了这个错误,我不知道它的来源:

android.app.ServiceConnectionLeaked: Service     com.merchantech.app.smartdiscount.MyIntentService has leaked ServiceConnection  com.clover.sdk.v3.order.OrderConnector@535008f4 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1426)
        at android.app.ContextImpl.bindService(ContextImpl.java:1415)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.clover.sdk.v1.ServiceConnector.connect(ServiceConnector.java:119)
        at com.clover.sdk.v1.ServiceConnector.waitForConnection(ServiceConnector.java:148)
        at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:209)
        at com.clover.sdk.v3.order.OrderConnector.getOrder(OrderConnector.java:153)
        at com.merchantech.app.smartdiscount.MyIntentService.onHandleIntent(MyIntentService.java:41)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.os.HandlerThread.run(HandlerThread.java:60)
Run Code Online (Sandbox Code Playgroud)

这是我的BrodcastReceiver类:

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals("com.test.intent.action.LINE_ITEM_ADDED")) {
            Intent i = new Intent(context, MyIntentService.class);
            context.startService(i);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的IntentService类:

public class MyIntentService extends IntentService { …
Run Code Online (Sandbox Code Playgroud)

service android broadcastreceiver intentservice

6
推荐指数
2
解决办法
2万
查看次数

收集IntStream进行映射时出错

以下代码

String[] values = ...
.... 
Map<String, Object> map = new HashMap<>();
for (int i = 0; i < values.length; i++) {
    map.put("X" + i, values[i]);
}
Run Code Online (Sandbox Code Playgroud)

由IntelliJ转换为:

Map<String, Object> map = IntStream.range(0, values.length)
        .collect(Collectors.toMap(
                i -> "X" + i,
                i -> values[i],
                (a, b) -> b));
Run Code Online (Sandbox Code Playgroud)

这可以缩短为

Map<String, Object> map = IntStream.range(0, values.length)
            .collect(Collectors.toMap(
                    i -> "X" + i,
                    i -> values[i]));
Run Code Online (Sandbox Code Playgroud)

2个流版本无法编译.

IntelliJ,暗示值[i]中的i存在问题:

不兼容的类型.
必需:int
Found:java.lang.Object

编译器抱怨:

错误:(35,17)java:接口java.util.stream.IntStream中的方法collect不能应用于给定的类型;
required:java.util.function.Supplier,java.util.function.ObjIntConsumer,java.util.function.BiConsumer
found:java.util.stream.Collector>
reason:无法推断类型变量R
(实际和正式)参数列表长度不同)

有谁能解释为什么?

java javac intellij-idea java-8 java-stream

6
推荐指数
1
解决办法
2251
查看次数

如何更改prometheus指标的终点

我试图将一些指标从spring-boot服务公开给prometheus.不幸的是,spring-boot执行器和prometheus simple-client都通过/ metrics端点暴露了它们的指标.

如何更改simple-client的端点?

谢谢

spring-boot prometheus

3
推荐指数
2
解决办法
5403
查看次数

Sleuth 不显示跟踪 ID 和跨度 ID

我正在尝试运行 Spring Boot 应用程序并在 Sleuth 的支持下跟踪其执行情况。日志显示服务名称,但没有显示跟踪 ID 或跨度 ID。我得到的只是 [myservice,,,]。

我错过了什么?

以下是日志中的一些行。

2017-04-30 14:41:38.750 INFO [myservice,,,] 7 --- [main] scaAnnotationConfigApplicationContext:刷新 org.springframework.context.annotation.AnnotationConfigApplicationContext@5e57643e:启动日期 [4 月 30 日星期日:184:44]格林威治标准时间 2017];上下文层次结构的根

2017-04-30 14:41:39.264 INFO [myservice,,,] 7 --- [main] faAutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' 注释被发现并支持自动装配

...

谢谢

spring-boot spring-cloud-sleuth

1
推荐指数
1
解决办法
3673
查看次数