java是数据线。getMicrosecondPosition()线程安全?
假设我在一个线程中使用DataLine.write()
,在另一个线程中读取DataLine.getMicrosecondPosition()
。读线程会看到写线程的更新吗,还是我应该同步代码以保证可见性
你可以在下面搜索框中键入要查询的问题!
假设我在一个线程中使用DataLine.write()
,在另一个线程中读取DataLine.getMicrosecondPosition()
。读线程会看到写线程的更新吗,还是我应该同步代码以保证可见性
# 1 楼答案
我想说清楚:
write()
是一个潜在的阻塞调用,它将数据放入行的缓冲区以呈现。也就是说,该行可能会在未来某个时间呈现数据。从docs开始:getMicrosecondPosition ()
告诉您已经渲染了多少微秒,docs:这两种方法都应该是线程安全的,因为Javadocs中没有警告