小编Kon*_*rdź的帖子

在Java中执行简单异步任务的最佳方法?

我想异步调用一个与主线程分开的函数.我是Java并发的新手,所以我问这样做的最佳方法是什么:

for(File myFile : files){
    MyFileService.resize(myfile)  <--- this should be async
}
Run Code Online (Sandbox Code Playgroud)

while循环继续,而函数MyFileService.resize在后台运行,我的每个文件都在集合中.

我听说Java8的CompletionStage可能是很好的方法.什么是最好的方法?

java concurrency asynchronous

3
推荐指数
1
解决办法
9368
查看次数

Angular Material MatChipList 不会触发更改,也不会选择事件

我正在尝试向用户显示具有预定义值的芯片列表,并让用户选择其中的一些。我的目标是通过点击选择多个筹码,并根据反应做出反应。

问题是,没有发出单个事件。

我做错了什么?

manage-roles.component.html

<mat-chip-list [selectable]="true" [multiple]="true"
  (change)="onChange($event)">
  <mat-chip *ngFor="let role of possibleRoles"
            [selectable]="true" (selectionChange)="onChipSelect($event)">
    {{role}}
  </mat-chip>
</mat-chip-list>
Run Code Online (Sandbox Code Playgroud)

manage-roles.component.html

@Component({
  selector: 'hr-manage-roles',
  templateUrl: './manage-roles.component.html'
})
export class ManageRolesComponent implements AfterViewInit {
  @ViewChild(MatChipList) chipList: MatChipList;
  possibleRoles: string[] = Roles; // some const

  ngAfterViewInit(): void {
    this.chipList.chipSelectionChanges.subscribe(change => {
      console.log(change); // not fires
    })
  }

  onChange(change: MatChipListChange){
    console.log(change); // not fires
  }

  onChipSelect(change: MatChipSelectionChange) {
    console.log(change); // not fires
  }
}
Run Code Online (Sandbox Code Playgroud)

包.json

  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/cdk": "^5.0.0",
    "@angular/common": "^5.1.0",
    "@angular/compiler": "^5.1.0", …
Run Code Online (Sandbox Code Playgroud)

angular-material angular

3
推荐指数
1
解决办法
8423
查看次数

如何测试这个文件写入,3lines 功能?

这是我在某个服务类中的方法。它是公开的,因此应该进行测试。我只是不知道我应该测试什么。我会模拟Writer和 spyOn 函数调用,但是使用这种实现是不可能的(不是吗?)

我正在使用MockitoJUnit

现在,我只能使函数抛出和断言该异常

有什么帮助吗?

@Override
public void initIndexFile(File emptyIndexFile) {
    try {
        Writer writer = new FileWriter(emptyIndexFile);
        writer.write("[]");
        writer.close();
    } catch (IOException e) {
        throw new IndexFileInitializationException(
            "Error initialization index file " + emptyIndexFile.getPath()
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

java testing unit-testing mockito writer

2
推荐指数
1
解决办法
5591
查看次数

为什么这些Date对象不同?

我想知道为什么这两个Date对象在控制台中有不同的输出.在我看来它应该是相同的,但我可能是错的:)

var twoLinesSetup = new Date();
twoLinesSetup.setHours(0, 0, 0);
var inlineSetup = new Date().setHours(0, 0, 0)

console.log('twoLinesSetup', twoLinesSetup);
console.log('inlineSetup', inlineSetup);
Run Code Online (Sandbox Code Playgroud)

和控制台

twoLinesSetup:2017年5月8日星期一00:00:00 GMT + 0200

inlineSetup:1494194400521

为什么会这样?

javascript date

1
推荐指数
1
解决办法
65
查看次数