How to properly implement Multi-threading in a JavaFX MVMM application [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm looking for a way to thread the ViewModels in a MVVM Architecture, without having to use tasks everywhere.
My ideal solution would be :
1 Application Thread (with the view)
1 Background Thread (with the viewModel)
Message passing between the 2
ViewModels still behave as normal Java Classes w/o Tasks/Service/Platform.runlater in every method
Is there a way to do this without bloating the code ?

This is probably not going to work the way you would like it to work. The view-models normally communicate with the views via bound properties. Therefore the properties of the view-models must always be updated on the application thread.
The proposed JavaFX way of dealing with concurrent background activities is to use Services. But if you don't like that it maybe worth it to have a look here: https://github.com/ReactiveX/RxJavaFX

Related

I'm new at programming. I'm not sure how much to use methods [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So, I just finished my first program, but I haven't use any methods in it, since I'm just beginning to learn how to use them. Here's the original code : http://codepad.org/JiBfJI8Q I started to fractionate it but realised that it would be a method inside another all the way down. Is that actually the way to do it, or did I get the idea wrong?
without having looked at your code:
The general idea of methods is to separate small
portions of code which might be used at multiple other places in your code.
so yes, calling methods from within other methods is a good thing to do.
ideally your so called "composed methods" read out like a little story:
public void transaction(){
openDatabaseConnection();
addRecordsToDatabase();
closeDataseConnection();
}

How to call a Thread in a method [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to programmatically move a Thread in another method. How I can do this?
that's entirely not possible in Java.
There are some ways around that - using tools like AtomicReferences, AtomicBoolean, wait/notify or Channels. With these tools, you could inform the other thread that it should do something specific.
Another approach would be to copy SwingUtilities invokeLater - like here: http://www.javamex.com/tutorials/threads/invokelater.shtml
However, I would like to ask the question why that method execution needs to be run in a specific thread? Wouldn't just another (new thread) be fine too? That should significally simplify your problem. In that case, just start a new thread to call that method

Best design practice with using methods that multiple fragments use [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am developing an Android unit conversion and calculator application in which I have a 3 fragment ViewPager set up and was wondering what would be the best OOP design practice when attempting to use methods over many fragments. Should I set up a centralized calculate method and call it within each fragment?
I currently have each fragment isolated with their calculations, spinner values, and intermediary values. I am also sending a result of a calculation from a fragment back to another fragment through an intent on the Main Activity.
My code currently works, but as I am learning more Java I would like to start piecing together best design practices and efficient code. Thanks for any insight!
If possible, i'd write something like CalculationUtils.java and define every common method inside, as public static, and later call them with CalculationUtils.method1(...)

How listeners work in java, where do they reside, what is it memory management? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
How Listeners works in JVM? Where they reside? What keeps track of them? I tried searching but couldnt find any references
From Oracle's Introduction to Event Listeners:
The event model, which you saw at its simplest in the preceding example, is quite powerful and flexible. Any number of event listener objects can listen for all kinds of events from any number of event source objects. For example, a program might create one listener per event source. Or a program might have a single listener for all events from all sources. A program can even have more than one listener for a single kind of event from a single event source.
Multiple listeners can register to be notified of events of a particular type from a particular source. Also, the same listener can listen to notifications from different objects.

How to create a custom EventProcessors in Disruptor? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am looking to create a custom EventProcessors in Disruptor but the documentation is very minimal. (https://code.google.com/p/disruptor/wiki/DisruptorWizard) How is this done. What are the concepts behind it and what are the issues and pitfalls?
Your question is very broad, so is my answer.
the concept behind the event processor is that it processes one event at a time in a single thread.
the issue is that you must decompose you system into asynchronous events.
pitfalls: it may be much more complicated than you need unless you really need millions of events per second. (And this is pretty rare out side HFT)

Categories