About threads in a service process

by rktb » Sat, 14 Mar 2009 05:01:19 GMT


Sponsored Links
 i,

- What do the methods startThreadPool() and joinThreadPool() do during
the process of launching a service, e.g., mediaplayer service in the
file main_mediaserver.cpp?
int main(int argc, char** argv)
{
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm = defaultServiceManager();
LOGI("ServiceManager: %p", sm.get());
AudioFlinger::instantiate();
MediaPlayerService::instantiate();
CameraService::instantiate();
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
}

- I have a service that I am using and see multiple threads on the
server side. Below is a snippet of the log.
03-13 19:52:58.143 26 45 V IMyTest: BnMyTest::onTrasact ...
tid=45
03-13 19:52:58.143 26 44 V IMyTest: BnMyTest::onTrasact ...
tid=44
03-13 19:52:58.183 26 26 V IMyTest: BnMyTest::onTrasact ...
tid=26
03-13 19:52:58.213 26 45 V IMyTest: BnMyTest::onTrasact ...
tid=45
03-13 19:52:58.213 26 44 V IMyTest: BnMyTest::onTrasact ...
tid=44
03-13 19:52:58.233 26 45 V IMyTest: BnMyTest::onTrasact ...
tid=45
03-13 19:52:58.233 26 26 V IMyTest: BnMyTest::onTrasact ...
tid=26
03-13 19:52:58.233 26 184 V IMyTest: BnMyTest::onTrasact ...
tid=184

If I read this correctly, the service is running on a process with
pid=26. But, the "onTransact" calls happen on multiple threads. I did
verify that the "Transact" calls occur in all one thread (on the
application process). Though there appear to be multiple threads (ids)
running, it looks like the calls are serialized. How come there are
multiple threads? Is there a way to control the number of threads
running on the server process?


Thanks,
Ravi


On Feb 12, 3:13pm, rktb <yend...@pv.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by Freepine » Sat, 14 Mar 2009 08:50:13 GMT


 tartThreadPool() will spawn a new thread into the thread pool which talks
with binder driver, while joinThreadPool() will put the calling thread
itself into thread pool.

It seems there is no API to control the maximum number of binder threads in
the pool, and sometimes driver will tell the process to spawn new thread
automatically via BR_SPAWN_LOOPER command.

On Sat, Mar 14, 2009 at 1:01 PM, rktb <yend...@pv.com> wrote:


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


About threads in a service process

by rktb » Sat, 14 Mar 2009 13:34:40 GMT


 ut, these threads don't run concurrently...right? I am trying to
understand what kind of precautions the native library needs to take
in the case of multiple threads.

-Ravi

On Mar 14, 3:49am, Freepine <freep...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by Dianne Hackborn » Sun, 15 Mar 2009 02:17:21 GMT


 es they run concurrently, that is why they are separate threads. :)

Currently the maximum number of threads in a process's thread pool is 16.

On Sat, Mar 14, 2009 at 6:34 AM, rktb <yend...@pv.com> wrote:



--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support. All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Sun, 15 Mar 2009 03:05:32 GMT


 ianne's earlier response on binders and services:
http://groups.google.com/group/android-developers/msg/d76e607aa62c1cad



On Mar 14, 9:17pm, Dianne Hackborn <hack...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Sun, 15 Mar 2009 03:09:43 GMT


 hanks Dianne.

I think I am missing something very basic here. Please help me out.
The way I understand it, atleast through the logs, all IPC calls
across the binder are synchronous, i.e., Transact and corresponding
OnTransact calls are serialized. Then, how could the threads run
concurrently? Is this the case when two applications are accessing the
same service?

-Ravi

On Mar 14, 9:17pm, Dianne Hackborn <hack...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Sun, 15 Mar 2009 04:10:49 GMT


 nother article about threads and binders:
http://www.angryredplanet.com/~hackbod/openbinder/docs/html/BinderThreading.html

On Mar 14, 10:09pm, rktb <yend...@pv.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by Dave Sparks » Mon, 16 Mar 2009 17:04:37 GMT


 nless otherwise specified, all binder calls are synchronous to the
calling process (usually referred to as the client process). They are
completely asynchronous to the callee (usually referred to as the
server process).

What this means is that the caller will block in the binder call until
the server thread has completed the requested action. On the server
side, the binder request is picked up by on the worker threads, it
proceeds serially until the work is complete, and then returns the
result to the caller across the binder. It is possible for multiple
worker threads to be concurrent within the server process acting on
behalf of different clients, and perhaps even different threads of the
same client.

On Mar 14, 8:09 pm, rktb <yend...@pv.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Mon, 16 Mar 2009 21:15:36 GMT


 hanks Dave.

On Mar 16, 12:04pm, Dave Sparks <davidspa...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Notification manager problem

Hi, I'm trying to set a notification from my application and when a
user click the notification it will open my application with the data.
the notification works fine, but the my application also get launch
when the notification being set. I thought the intent that I set up in
pending intent will only get launch when the notification is clicked
by the user.

The code for setting up the notification

 protected void showNotification() {
        // look up the notification manager service
        NotificationManager nm =
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        Intent newIntent = new Intent(Intent.ACTION_VIEW, mUri, this,
NoteEdit.class);
        newIntent.putExtra(getString(R.string.clear_notification),
true);
        newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // The PendingIntent to launch our activity if the user
selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this,
0,
                        newIntent, 0);

        // The ticker text, this uses a formatted string so our
message could be localized
        String tickerText =
getString(R.string.note_reminder_notification) + " " + mTitle;

        // construct the Notification object.
        Notification notif = new
Notification(R.drawable.ic_notification, tickerText,
                System.currentTimeMillis());

        // Set the info for the views that show in the notification
panel.
        notif.setLatestEventInfo(this, mTitle, mNote, contentIntent);

        // after a 100ms delay, vibrate for 250ms, pause for 100 ms
and
        // then vibrate for 500ms.
        //notif.vibrate = new long[] { 100, 250, 100, 500};

        // Note that we use R.layout.incoming_message_panel as the ID
for
        // the notification.  It could be any integer you want, but we
use
        // the convention of using a resource id for a string related
to
        // the notification.  It will always be a unique number within
your
        // application.
        int notifId = R.string.note_reminder_notification + mId;
        nm.notify(notifId, notif);
    }

Anybody can give me some pointer why it's doing this? Is there anyway
to get the sender info of an intent on the receiver side?

Thanks
--~--~---------~--~----~------------~-------~--~----~

2. Context from which to initiate Service via Alarm Manager; Application Model Questions

I've created a simple app. to help me better understand a few key
components in the real app I'm making.  A snippet of what I've done:

- an Activity is launched (lets call it the Home Activity) -> from
here I schedule an alarm -> the alarm sets off a Pending Intent that
starts a Service.

- the above steps appear to do what I want them to do.

My questions:

- is a scheduled alarm persistent with respect to its creating process
(I believe so) ?  If the Home Activity is destroyed, the alarm still
goes off, correct?

- the PendingIntent that the alarm calls as well as the Intent nestled
within both have a Context of the Home Activity.  Is this a problem?
Does the system launch the Home Activity again (if it has been
destroyed since scheduling the alarm) just to launch the Service?

- the Service does its task (some networking which will take a couple
seconds) and then possibly creates a notification before killing
itself (the alarm is repeating so it will get called again later).
Does the Service need to make a new Thread to do its work in?  The
user is not interacting with the Home Activity at this point so I
don't think a new Thread is needed.

I think that sums up my questions for now.  Advice will be greatly
appreciated!

--~--~---------~--~----~------------~-------~--~----~

3. Windows ADB Driver?

4. adb devices command sees multiple offline devices attached - but it's the same device

5. SDCard and SQLiteOpenHelper problem

6. : How to stops the activity from getting restarted when mode changes from LandScape to Portrait or vice-versa

7. activity doesn't seem to end, despite calling .finish()...