Yimo 的讨论

发布于: 雪球回复:0喜欢:2
举个例子吧,我想知道java里future.get多次调用是不是总能得到相同的结果,这个是谷歌给我的第一个链接 网页链接
而这个是perplexity的回答
No, future.get() does not always return the same results through multiple invocations. The behavior depends on the implementation of the Future and the asynchronous operation it represents.
In Java, a Future represents the result of an asynchronous computation. When you call future.get(), it blocks until the asynchronous operation completes and returns the result of that operation. However, if you call get() multiple times on the same Future instance, the behavior can vary:
1. If the Future represents a one-time computation, calling get() multiple times will return the same result after the initial computation completes.[1] Subsequent calls to get() will not trigger a new computation.
2. If the Future represents a recurring or stateful operation, calling get() multiple times may return different results each time, depending on the implementation.[1] For example, if the Future represents a periodic task or a stateful service, each call to get() could return a new result based on the current state.
3. If the asynchronous operation fails with an exception, calling get() will throw that exception on the first invocation. Subsequent calls to get() on the same Future instance will continue to throw the same exception.[1]
In summary, the behavior of multiple invocations of future.get() depends on the semantics of the asynchronous operation represented by the Future. If it's a one-time computation, get() will return the same result after the initial computation. If it's a recurring or stateful operation, get() may return different results on each invocation. And if the operation fails, get() will consistently throw the same exception.[1]
Citations:
[1] 网页链接
[2] 网页链接
[3] 网页链接
[4] 网页链接
[5] 网页链接
st上的回答简单直接有效,ai的回答也不能说错,但总有点不着边际抓不住重点,看完还是有点不确定,但也想不出怎么进一步发问。
ai某些时候更高效,但google更能发挥主观能动性,减少"问了感觉还是白问"的机率,当然有经验的用户会知道某类问题在哪个平台问更有效