concurrency

Javafx Task - update progress from a method

时光毁灭记忆、已成空白 提交于 2021-02-06 12:59:41
问题 In a JavaFX application I wish to update a status bar according to some work logic which I've implemented in an other class. I can't figure out how to combine my desire to pass to work logic to the method (and not to write it inside the task) and to know about the work progress percentage. This is an example of the controller with the Task: public class FXMLDocumentController implements Initializable { @FXML private Label label; @FXML ProgressBar progressBar; @FXML private void

Javafx Task - update progress from a method

半腔热情 提交于 2021-02-06 12:59:05
问题 In a JavaFX application I wish to update a status bar according to some work logic which I've implemented in an other class. I can't figure out how to combine my desire to pass to work logic to the method (and not to write it inside the task) and to know about the work progress percentage. This is an example of the controller with the Task: public class FXMLDocumentController implements Initializable { @FXML private Label label; @FXML ProgressBar progressBar; @FXML private void

Real-world examples for ABA in multithreading [closed]

笑着哭i 提交于 2021-02-06 02:40:34
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm looking for some nice real-world examples of the ABA-problem causing trouble in multithreaded code. The ABA-problem occurs in

Real-world examples for ABA in multithreading [closed]

一世执手 提交于 2021-02-06 02:34:57
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm looking for some nice real-world examples of the ABA-problem causing trouble in multithreaded code. The ABA-problem occurs in

Real-world examples for ABA in multithreading [closed]

ぃ、小莉子 提交于 2021-02-06 02:34:19
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm looking for some nice real-world examples of the ABA-problem causing trouble in multithreaded code. The ABA-problem occurs in

Break out of select loop?

时光毁灭记忆、已成空白 提交于 2021-02-05 20:19:57
问题 I'm trying to use a select in a loop to receive either a message or a timeout signal. If the timeout signal is received, the loop should abort: package main import ("fmt"; "time") func main() { done := time.After(1*time.Millisecond) numbers := make(chan int) go func() {for n:=0;; {numbers <- n; n++}}() for { select { case <-done: break case num := <- numbers: fmt.Println(num) } } } However, it doesn't seem to be stopping: $ go run a.go 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Is there a difference between concurrency and parallelism in java?

烂漫一生 提交于 2021-02-05 12:56:39
问题 I have been doing some research in Google and cant quite get my head around the differences (if any) between concurrent and parallel programs in java. Some of the information I have looked at suggests no differences between both. Is this the case?? 回答1: It depends on who is defining it. The people who created the Go programming language call code Concurrent if it is broken up into pieces which could be treated in parallel, whereas Parallelism implies that those pieces are actually running at

automatic update jtextfield

最后都变了- 提交于 2021-02-05 11:37:55
问题 Does anyone know how to update a jTextfield every 5 secondes? Automatic. So no userinput is required. It is used to update time in a textfield. This is what i tried but then my program freezes. while(true){ Thread.sleep(1000); txtCheck.setText(convert.getCheck()); System.out.println("Ja"); } convert is a thread, i tried to throw an exception but failed, cause Eclise says Threads can't throw exceptions. Convert.getCheck: public String getCheck() { return check; } 回答1: You want to use a Swing

Awaiting a sequence of tasks to run sequentially

梦想与她 提交于 2021-02-05 11:28:26
问题 I would like to create a generic method to await for a sequence of tasks to finish sequentially, retrieving the result of each one. This is the code I've created: public static class TaskMixin { public static async Task<IEnumerable<T>> AwaitAll<T>(this IEnumerable<Task<T>> tasks) { var results = new List<T>(); foreach (var t in tasks) { results.Add(await t); } return results; } } Is there a better or built-in way to do it? Notice Before writing the above method I tried with the built-in Task

Can you specify a non-static lifetime for threads? [duplicate]

心已入冬 提交于 2021-02-05 09:14:26
问题 This question already has answers here : How can I pass a reference to a stack variable to a thread? (1 answer) Thread references require static lifetime? (1 answer) How do I use static lifetimes with threads? (2 answers) How can I send non-static data to a thread in Rust and is it needed in this example? (1 answer) Closed 1 year ago . Here's a toy example of my problem: use std::sync::{Arc, Mutex}; fn operate_in_chunks(vec: &mut Vec<f32>) { let chunk_size = 10; let mutex_vec: Arc<Mutex<&mut