java为什么没有未来。得到(…)杀线?
我有一个应用程序正在使用future进行异步执行
我在get方法上设置了参数,当线程没有得到响应时,它应该在10秒后被终止:
Future<RecordMetadata> meta = producer.send(record, new ProducerCallBack());
RecordMetadata data = meta.get(10, TimeUnit.SECONDS);
但是线程在60秒后被杀死:
java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:1124)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:823)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:760)
at io.khinkali.KafkaProducerClient.main(KafkaProducerClient.java:49)
Caused by: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
我做错了什么
# 1 楼答案
从docs开始:
检查logback中的Kafka Appender配置。xml,查找:
# 2 楼答案
如果我们谈论的是
Future.get(...)
,那么它根本就不会“杀死”线程。引用javadocs,Future.get(...)
方法:如果} ,但即使这样也不能保证线程将被“杀死”。这会导致线程中断,这意味着certain methods will throw ^{} 或线程需要检查
get(...)
方法超时,那么它将抛出TimeoutException
,但是您的线程可以继续运行。如果要停止线程运行,则需要捕获TimeoutException
,然后调用^{Thread.currentThread().isInterrupted()
是的,这个超时与
Future.get(...)
超时无关