我正在使用fork / join编写Java多线程程序。当我两次调用fork / join池时,它只会执行一次,为什么?
fun doCustom() {
/* This method uses the custom_dialog.xml file created for greater control over
the styling of the Custom Alert Dialog for various screen sizes and to be
able to set the text size of the dialog message text
*/
val makeDialog = LayoutInflater.from(this).inflate(R.layout.custom_dialog,null)
val mBuilder = AlertDialog.Builder(this).setView(makeDialog)
val mAlertDialog = mBuilder.show()
val btnYES = makeDialog.findViewById<Button>(R.id.btnYES)
val btnNO = makeDialog.findViewById<Button>(R.id.btnNO)
mAlertDialog.setCancelable(false)
btnYES.setOnClickListener {
removePerson()
mAlertDialog.dismiss()
}
btnNO.setOnClickListener {
message("Record NOT Deleted")
etPerson.setText("")
Timer().schedule(800){
thisACTIVITY()
}
mAlertDialog.dismiss()
}
mAlertDialog.show()
}
private fun removePerson() {
val dbHandler = DBHelper(this)
val result = dbHandler.deletePerson(etPerson.text.toString())
if (result) {
etPerson.setText("")
message("Record Removed")
Timer().schedule(1000){
thisACTIVITY()
}
}else{
etPerson.setText("NO MATCH -> click View Person List")
btnViewList.visibility = View.VISIBLE
btnEdit.visibility = View.INVISIBLE
btnDelete.visibility =View.INVISIBLE
btnAdd.visibility = View.INVISIBLE
message("NO Match Found")
}
}
输出: 标记
答案 0 :(得分:0)
这是因为您要提交同一任务实例以多次执行。每个实例只能执行一次(除非您在再次提交之前使用ArrayList
方法...但是,通常您将只创建一个新的任务实例)。