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 10 days ago.
Improve this question
I got a class that is extending JInternalFrame. This class generates a bunch of objects (several hundred) that all are doing 3rd party API calls and so on. I am wondering, are all this class Objects (List of Custom obbjects) inside the JInternalFrame class destroyed once I click on the "x" to close the InternalFrame? If not, how can I react to the "click x" event to set the List of Objects to null and save memory?
When you click X you should expect the window to vanish from the screen.
But it is not guaranteed whether it will be disposed by the garbage collector.
If any of the main program, or more specifically any runnign thread still holds a reference to the JInternalFrame it will remain in memory. And the same can be said for the other objects it created: As long as a running thread has a reference, or a referenced object has a reference these objects will not be garbage collected.
From the amount of information you disclosed it can definitely not be said what is going to happen. Not even with a JInternalFrameListener.
Related
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
In a spring boot web application, I need to be able to do two tasks.
Tasks
Always check on the serial port if there is some data to read. Somebody can have passed a card on the scan. I think this task needs to start with the application.
If a new member comes, I need to scan a card, task 1 needs to be suspended/stopped... if the card is not assigned to anybody, it's assigned to this member. Restart task 1.
I don't know what is the best way to do task 1 to facilitate task 2.
I see there are many possibility: #Scheduled, TaskScheduler who will execute a thread...
Any suggestions?
You should make one Thread that reads data from the serial port in a loop and dispatches this data as events when something usefull was readed to a proper service that will serve this.
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.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
What is the difference between them? I know that
A queue is designed to have elements inserted at the end of the queue, and elements removed from the beginning of the queue.
Where as Dequeue represents a queue where you can insert and remove elements from both ends of the queue.
But which is more efficient?
Plus what's the difference between them two? Because I have a bit of knowledge about them, what I said above, but I would like to know more about them.
Deque is short for "double ended queue". With an ordinary queue, you add things to one end and take them from the other. With a double ended queue, you can add things to either end, and take them from either end. That makes it a bit more versatile; for example, you could use it as a stack if you wanted to.
In terms of efficiency, it really depends on the implementation. But generally speaking, you wouldn't expect a deque to outperform a queue, because a (single ended) queue could be implemented in a way that doesn't allow objects to be added or removed at the "wrong" end. Whereas any implementation of a deque would also work as an implementation of a queue.
Deque and queue are abstract data types that can be implemented in different ways. To talk about performance you have to specify which implementations you want to compare and which operation(s) you're interested in. Even better, do the benchmark yourself with the workload your application has and in the environment you're going to use (hardware, operating system, JVM version).
Since every deque is also a queue, in general you can say that deques can be at most as good as a queues.
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 7 years ago.
Improve this question
I have some problems with the order of method in my app. How i can take the control of time in an Android app? How i can know how many time is elapsed from the start of app? For more accuracy, I would say at 3 seconds from the start of this app, i want make happen this, like an invisible chronometer that, at one second, applies a method that i choose. I hope the question is easy to understand. Thanks in advance!
If You want to run task at once only you can use
new Timer().schedule(task, after);
And for multiple time execution
new Timer().scheduleAtFixedRate(task, after, interval);
for more details java.util.Timer.
Take a look of this library, Hugo
https://github.com/JakeWharton/hugo
With this you can control how many time elapsed in the methods.
To control how many time elapsed from app start until, for example, first activity is shown you have to:
First, extends Application class, you have and example here
http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
In the onCreate method of that class, save the time with System.currentTimeMillis() method
Then create a static method
public long getCurrentTimeFromStart() {
long current = System.currentTimeMillis();
return mInitialTime - current;
}
Call this method in onCreate method of your MainActivity or only the first time is called onResume for a more accurate time.
And for the last question you can use #Keyur Lakhani answer and user Timer class to schelude Runnables
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 8 years ago.
Improve this question
I have an interesting scenario based question related to java threads.
Sam has designed an application. I t segregates tasks that are critical and executed frequently from tasks that are non critical and executed less frequently. He has prioritized these tasks based on their criticality and frequency of execution. After close scrutiny, he finds that the tasks designed to be non critical are rarely getting executed. From what kind of problem is the application suffering?
I have figured it out as "Starvation" but i am still confuse whether I am right or wrong.
Starvation is a reasonable term for what is going on here. However, your lecturer might have something more specific in mind (... I'm not sure what ...) so check your lecture notes and text books.
... i am still confuse whether I am right or wrong.
If you stated why you are confused, we might be able to sort out your confusion.
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 working on a android application where shake detection is required, which is already implemented and working perfect. I am using Accelerometer to detect shake.
Here is my question:
Current implementation is using/listening sensor on main UI thread, which is working perfect as of now. But still I am confused about the best practice to use the sensor, what it is? to run on Main Thread or on Separate Thread?
if Main Thread, its pretty clear me.
if your suggestion is Separate Thread, then why so?
One more thing, on the name of processing after shake detection, I am doing network request which is on Separate Thread, so no load of after detecting shake, only thing I care about is how costly it is to Start Listening to a sensor on main thread.
With simple sensor detection it is more than adequate to use the main UI thread. Starting up a separate thread with sensors would require a handler and thread cleanup. You are adding unnecessary steps.
If you are already pushing your ui you are likely better off moving some of your other bulk off of the main thread. Sensors are just handled really efficiently with Android already, moving it off the thread won't help as much as it could hurt if you aren't careful.
Now performing operations on the data you get from sensors (like location from GPS) is a whole different ballgame, and something that will very possibly need it's own thread.