鉴于此代码:
Element elem = new Element.html("<p>This is a paragraph.</p>");
document.body.append(elem);
document.body.children.add(elem);
document.body.nodes.add(elem);
Run Code Online (Sandbox Code Playgroud)
结果都是一样的,当我add到body.children或body.nodes.两者有什么区别?哪个更好?
我正在使用带有分区键 =“deviceId”的文档数据库。下面的2个代码有什么不同:
var fo = new FeedOption{ PartitionKey= new PartitionKey("A1234") };
var partitionKeyInQuery= dbClient.CreateDocumentQuery(d => d.deviceId = "A1234" and d.type==1, fo);
var noPartitionKeyInQuery = dbClient.CreateDocumentQuery(d => d.type==1, fo);
Run Code Online (Sandbox Code Playgroud)
在 FeedOption 中应用 PartitionKey 时,我应该在 WHERE 子句中添加“deviceId”吗?
我正在使用 DocumentDB。给定索引策略:
消息类型:字符串 - 精度 -1
设备编号 : 字符串 - 精度 -1
查询 1:
SELECT * FROM c WHERE c._ts >= 1563721200 AND c._ts < 1563807600 AND c.messageType = 'attack' AND c.deviceId >= 'A' AND c.deviceId < 'Z'
Run Code Online (Sandbox Code Playgroud)
查询 2:
SELECT * FROM c WHERE c._ts >= 1563721200 AND c._ts < 1563807600 AND c.messageType = 'attack' AND c.deviceId >= 'A' AND c.deviceId < 'Z' ORDER BY c._ts DESC
Run Code Online (Sandbox Code Playgroud)
执行代码:
var query = dbClientSource.CreateDocumentQuery<Document(UriFactory.CreateDocumentCollectionUri(db, collection),
sql,
new FeedOptions { MaxItemCount …Run Code Online (Sandbox Code Playgroud)
我正在开发一个API.此API需要执行2次DB查询才能获得结果.
我尝试了以下策略:
在Service中创建2个线程(使用Callable和CoundownLatch)并行运行2个查询并检测完成时间.
public class PetService {
public Object getData() {
CountDownLatch latch = new CountDownLatch(2);
AsyncQueryDBTask<Integer> firstQuery= new AsyncQueryDBTask<>(latch);
AsyncQueryDBTask<Integer> secondQuery= new AsyncQueryDBTask<>(latch);
latch.await();
}
public class AsyncQueryDBTask<T> implements Callable {
private CountDownLatch latch;
public AsyncQueryDBTask(CountDownLatch latch) { this.latch = latch;}
@Override
public T call() throws Exception {
//Run query
latch.countDown();
}
Run Code Online (Sandbox Code Playgroud)它工作正常,但我觉得我正在破坏Spring的结构.
我想知道在Spring 4中获取数据的最有效方法是什么.
- 如何知道运行自己查询的2个线程完成了他们的工作?
- 如何控制线程资源,如使用和释放线程?
提前致谢.