I am running a Thread to do some looped tasks. but there is a problem while doing the tasks and if the app switched The Thread getting very slow and there is huge delay in the tasks to be done any idea why the thread get slower if the app switched ?
Related
I am facing a problem with my Android App.
My application get a microphone by using Native Code in C and other services like MQTT.
But actually my app use a lot of CPU usage and a notification request the user to set my app on a deep sleep mode.
So I'm searching what part of my code use as much CPU and when I start CPU Profiler I see some Thread that use a lot of CPU but I don't know what part of my code it is.
My question is : How to know what Thread indicate in the CPU Profiler, corresponds to which service or thread of my code.
Thanks in advance.
I solved my problem basically by setting a name to my thread like that :
thread.setName("MainActivity_Thread");
This allow to display the name of the thread to the CPU Profiler.
I'm a hobbyist programmer and have written a small application using Python3 and Gtk3.
It has two threads in it. One is a simple clock showing current time and updating the GUI every minute. The other is a countdown timer which can be started and stopped (the thread is killed with a flag on pause, and a new thread created on start). Both threads are daemons and neither interacts with the other.
It is working perfectly in linux.
In Windows it freezes / locks up, even when I haven't started the timer (i.e. only the clock thread is active). Windoze complains: "Python.exe is not responding".
My initial question is just whether it is safe to use threads in Windows. Or perhaps it is not a good idea to use GTK3?
Has anyone else experienced something like this?
is it possible to fire up an event at a specified time interval in BlackBerry? I'm looking for something similar to AlarmManager class in Android (if anyone is familiar with it).
The goal is to is to run some code, even when the application is not in foreground and without it gaining foreground "focus". Preferably it should be possible to fire the event even if the app was killed by system or by phone reboot (I do not know the details about killing apps at this OS, I'm beginning development now).
I would prefer not to write a background process for this task as it is going to be fired every few hours (I think it would be a waste of battery to use a background task for a simple alarm-like event).
I've looked around a lot, but I cannot find any satisfying solution.
cheers,
kajman
The Timer and TimerTask classes are useful for running a task on a schedule. Take a look at the APIs here:
http://www.blackberry.com/developers/docs/7.0.0api/java/util/Timer.html
The Timer will create its own Thread and sleep until it has a task to run. It would involve having a background task running but it wouldn't be using an CPU or battery if it is just waiting.
If you don't want a Thread running all of the time you can use the ApplicationManager class to schedule your application to start later.
You can also configure your app to run on start up. The OS generally won't kill your apps unless you have a coding error. RIM refers to this as the Always-On Experience in their Super App document:
http://docs.blackberry.com/en/developers/deliverables/23567/Always_on_1380986_11.jsp#Keeping_the_app_running_1381022_11
I just moved from WinXP to Win7.
My software needs to have real time response to I/O so it makes a busy-wait in one thread (which has affinity to run on one CPU).
The result is 100% CPU on one of the cores and 0% CPU for others, on Winows XP it worked just fine.
In Windows 7 the system freezes. (The software is a console application, for Windows application it behaves a bit different. only if the main thread make busy-wait without peeking messages it freezes)
Any ideas ?
So you're using a non real-time OS for realtime I/O. Simply put the code isn't working correctly and should do a non busy-wait (change to a sleep-wait) loop and change the thread timer settings to something that is realtime enough.
See this question to setup windows for millisecond precision on a timer callback.
How to trigger a C# function at a certain time with millisecond precision?
If an app is brought to the background what happens to the UI Thread which was running this app?
Will it sleep or get killed?
When the app is back to foreground will the same thread be notified or a new thread will created and associated with the app instance?
I don't know specifically, but you should always program with the possibility that your Activity may be killed at any time that it is not in the foreground. Whether that involves killing the thread every time it enters the background, or causing the thread to sleep and then killing it if the Activity is killed, I don't know. In any case, you must assume it can and will happen, and program accordingly.
It depends on the memory situation. When your application goes into the background, it generally stays running initially. Android does not sleep your thread. It is up to you to stop updating your UI and performing calculations in on onPause.
However in low memory situations Android might kill application when it's the background (especially if you haven't been nice and are using up a load of resources). For this reason you should always save any persistant data in onPause.