我知道这个问题之前已被多次询问和回答,但我无法弄清楚互联网上的例子,比如这个或那个.
这两种解决方案都检查阻塞队列的数组/队列/链表的空白,notifyAll以及put()方法中的等待线程,反之亦然get().一个评论在第二环节强调了这一情况,并提到这是没有必要的.
所以问题是; 检查队列是否为空,对我来说似乎有点奇怪 完全通知所有等待的线程.有任何想法吗?
提前致谢.
java multithreading synchronization java.util.concurrent blockingqueue
我有相当复杂的对象结构(有一堆原始字段和对象引用),并且想要测试除了少数几个字段之外的所有字段.举个例子;
ComplexObject actual = generateMagically("someInput");
ComplexObject expected = ActualFunction.instance.workMagically(actual);
// we want to be sure that workMagically() would create a new ComplexObject
// with some fields are different than "actual" object.
// assertThat(actual, samePropertyValuesAs(expected)); would check all fields.
// what I want is actually; - notice that "fieldName1" and "fieldName2" are
// primitives belong to ComplexObject
assertThat(actual, samePropertyValuesExceptAs(expected, "fieldName1", "fieldName2"))
Run Code Online (Sandbox Code Playgroud)
由于我不想手动检查所有字段,我相信必须有一种方法来优雅地编写该测试.有任何想法吗?
干杯.