際際滷

際際滷Share a Scribd company logo
2006 JavaOneSM
Conference | Session TS-3742 |
Dancing While Gaming
Multitasking VMs (MVM)
on Real Devices
Jae Hyou Lee Yaniv Shani
Samsung Electronics Sun Microsystems, Inc.
www.samsung.com www.sun.com
TS-3742
2006 JavaOneSM
Conference | Session TS-3742 | 2
Goal
Deeper understanding of Multitasking
VM implementation on real devices
2006 JavaOneSM
Conference | Session TS-3742 | 3
Project Highlights
 A joint collaboration between Samsung
Electronics and Sun Microsystems
 MVM deployment is based on Suns JWC1.1.3
 Deploying most of the MSA JSRs
 Tested with hundreds of games and
applications from leading content providers
2006 JavaOneSM
Conference | Session TS-3742 | 4
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 5
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 6
What Is MVM?
 Running multiple applications simultaneously
 Java is always on
 Favorite applications instantly available
MP3 Playing
Chatting
Gaming
2006 JavaOneSM
Conference | Session TS-3742 | 7
MVM Conceptual View
Device H/W
Operating System
Native JVM Task
Configuration Level
MVM
Resource
Manager
App.
Manager
AMS
JSR JSR JSRJSR
Profile Level
Multitasking Safety
Isolation Model
Deployment Guidelines
Legacy Content
New App States
User Experience
Resource Policies
2006 JavaOneSM
Conference | Session TS-3742 | 8
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 9
Isolates and Tasks
Each application runs in its own logical Java
Virtual Machine, called an Isolate.
Within the JVM, each isolate is represented
as a Task. A task consists of one more Java
thread of execution.
2006 JavaOneSM
Conference | Session TS-3742 | 10
More on Tasks
 All tasks execute in the same single OS
task context
 All tasks share:
 Constant data structure
 Runtime support functions
 Each task encapsulates non-sharable
program state
MVM
2006 JavaOneSM
Conference | Session TS-3742 | 11
Implementation Details
 Each task has a separate, private copy of the static
variables of all the loaded Java classes
 Static variables are only global to all threads within
a particular task
Static Variable
class A {
public static int count;
...
}
Task 1
class A {
public static int count;
...
}
task 2
MVM
 Each task maintains a
private copy of count
 The Class representation
is shared
2006 JavaOneSM
Conference | Session TS-3742 | 12
Implementation Details
Synchronization
class A {
public static synchronized int open();
}
 Synchronization has to be task private
 Threads in one task cannot block threads in another task
Task 1 Task 2
MVM
A.open() A.open() A.open() A.open()
Blocking Threads Across
Tasks Isnt Allowed
2006 JavaOneSM
Conference | Session TS-3742 | 13
Resource Management
 The JVM is responsible for CPU time and
memory resources in order to ensure that all
tasks get their fair share
 Other resources, such as network bandwidth
and communication ports are managed by
the profile layer
2006 JavaOneSM
Conference | Session TS-3742 | 14
Resource ManagementScheduling
 Tasks and thread are
scheduled by the JVM
 Fair scheduling algorithm is
used for task scheduling in
order to prevent one task
from taking disproportionate
CPU time
 The Isolate class offers a
set of APIs to modify the
priority levels for each task
`
Task 2
Scheduler
MVM
Task 1
Active
Thread
MVM
2006 JavaOneSM
Conference | Session TS-3742 | 15
Resource ManagementMemory
 All tasks allocations are conducted from the
same global heap region
 The virtual machine has a bookkeeping
mechanism that accounts for each task total
heap memory consumption
 The JVM injects OutOfMemoryError as needed to
inform tasks that heap space has become scarce
2006 JavaOneSM
Conference | Session TS-3742 | 16
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 17
New MIDlet State in MVM
 An application is said to be in the Foreground when:
 Its displayable controls the display
 It handles event from the user input mechanism
 Only one MIDlet can execute in the Foreground at a time
Foreground MIDlet
2006 JavaOneSM
Conference | Session TS-3742 | 18
New MIDlet State in MVM
Background MIDlet
 An application is in the Background when:
 Its displayable does not control the display
 It does not handle the user inputs mechanism
 Zero or more MIDlets can execute in the Background
at a time
2006 JavaOneSM
Conference | Session TS-3742 | 19
The Application Manager
 A resident MIDIet
 Executed from power on
 Lists the running applications
 A fast way to switch between
running MIDlets
 Display background
MIDIets alerts
2006 JavaOneSM
Conference | Session TS-3742 | 20
Switching a MIDlet to the
Background (1/3)
 Upon a short Hot key press the foreground MIDlet
will be placed in the background and main device
menu will be displayed
Short Hot Key Press
Short Hot Key
2006 JavaOneSM
Conference | Session TS-3742 | 21
Switching a MIDlet to the
Background (2/3)
 Upon a long Hot key press the foreground MIDlet
will be placed in the background and the Application
manager dialog will be displayed
Long Hot Key
Long Hot Key
2006 JavaOneSM
Conference | Session TS-3742 | 22
Switching a MIDlet to the
Background (3/3)
Invoking Display.setCurrent(null)
 Upon calling setCurrent(null) the MIDlet will be placed
in the background and the idle screen of the device
will be displayed
Display.setCurrent(null)
2006 JavaOneSM
Conference | Session TS-3742 | 23
Interrupting the User
 Background MIDlet calls Display.setCurrent(alert)
 Background MIDlet tries to access a protected API
and a security dialog is prompted
 Noteworthy event occurred in the background
 e.g., Incoming IM while playing a game
2006 JavaOneSM
Conference | Session TS-3742 | 24
DEMO
User Experience Demonstration
2006 JavaOneSM
Conference | Session TS-3742 | 25
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 26
Managing Resources
 In a single-tasking environment, the MIDlet
has access to all of the available resources
 In a multitasking environment, MIDlets have
to compete for available resources
2006 JavaOneSM
Conference | Session TS-3742 | 27
Managing Resources
 Mechanisms
 Reservation
 Quota
 Revocation
 Policies
 Fixed partition
 Open for competition
 Special cases
2006 JavaOneSM
Conference | Session TS-3742 | 28
Resource Management Mechanisms
 A reservation mechanism sets aside a
certain amount of a resource for a MIDlet
and keeps it available for that MIDlet and
that MIDlet alone
Reservation
2006 JavaOneSM
Conference | Session TS-3742 | 29
Resource Management Mechanisms
 A quota mechanism permits a MIDlet to allocate
up to a certain amount of a resource; if the
MIDlet attempts to allocate more resources than
its quota, the attempt fails, even if resources are
actually available on the system
Quota
2006 JavaOneSM
Conference | Session TS-3742 | 30
Resource Management Mechanisms
 The system can revoke a resource from a
MIDlet and give it to another MIDlet
 Resource revocation examples:
 CPU cycles
 Display access
 Audio playback
 Resource revocation doesnt always have a
dramatic effect on the MIDlets execution
Revocation
2006 JavaOneSM
Conference | Session TS-3742 | 31
Resource Management Policies
 Initial amount of resources are reserved
before MIDlet launch
 Resource availability validation during
MIDlets startup
 Ensure consistent MIDlet behavior
Fixed Partition
2006 JavaOneSM
Conference | Session TS-3742 | 32
Resource Management Policies
 No reservation
 Resource are acquired and reclaimed at runtime
 May lead to unpredictable behavior
Open for Competition
2006 JavaOneSM
Conference | Session TS-3742 | 33
Special Resource
Management Policies
 Only the Foreground can access the LCD
display and receive key inputs events
 The current displayable of a Background
MIDlet is still updated
Note: vibrate() ,flashBacklight() and tone
playing arent honored when invoked from
a Background MIDlet
LCD Display
2006 JavaOneSM
Conference | Session TS-3742 | 34
Sound (1/2)
Special Resource
Management Policies
 Foreground MIDlets are assigned physical player that
can access the audio device resource
 Background MIDlets are assigned a logical player that
only maintains the audio state
 Upon foreground switch the player state is changed
automatically
Logical Player
Physical Player
1
Logical Player
Physical Player
2
Foreground
Switch
2006 JavaOneSM
Conference | Session TS-3742 | 35
Special Resource
Management Policies
 Unique JAD file property to lock audio resources
 Allows a background MIDlet to be audible
 Useful for media players (e.g., the MP3 player,
radio, etc.)
Sound (2/2)
1
Logical Player
Physical Player
2
Logical Player
Physical Player
1
Foreground
Switch
2006 JavaOneSM
Conference | Session TS-3742 | 36
A Full Resource Policy Matrix
Fixed Open Special
Memory X X
CPU X X
File Descriptor X X
Socket X X
Display X
Sound X X
Bluetooth X
Location X
PIM X
2006 JavaOneSM
Conference | Session TS-3742 | 37
Guidelines for Resource
Policy Selection
 Resource policy definition relies on the
underlying platform capabilities and
requirements
 Fixed partition policy should be used for
fundamental resources that are required by
the majority of the applications (e.g., memory,
file, socket)
 Open policy should be used resources that are
used by specific MIDlets and have limited
availability (e.g., Bluetooth, location)
 Display and sound requires special handling
2006 JavaOneSM
Conference | Session TS-3742 | 38
DEMO
Resource Policy Demonstration
2006 JavaOneSM
Conference | Session TS-3742 | 39
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 40
Multitasking Safety
 The native JVM task can run native code for
any task, hence the code must be made
aware of the task on whose behalf it is being
called and possibly allocating resources
 When the task context is established, the
code is considered multitasking safe
 Suns JWC software is multitasking safe
2006 JavaOneSM
Conference | Session TS-3742 | 41
Multitasking Safety
Implementation Guidelines
 In some cases a deployment of a profile to MVM
environment requires additional development in order
that the profile will execute properly
Foreground
Switch
Blocking Threads Across
Tasks Isnt Allowed
2006 JavaOneSM
Conference | Session TS-3742 | 42
Multitasking Safety
 At Java level, each task has a separate, private
copy of the static variables of all the loaded Java
classes
 This is handled internally by the MVM
 Native code often has global data
 Native data is shared across all tasks!
 Global native data needs to be replicated for
each task
 Held as a field of a Java object
 Proper handling for singleton depends on whether
it is meant be used on a per-task basis (the default
behavior for MVM), or by the entire system
Static and Global Variable
2006 JavaOneSM
Conference | Session TS-3742 | 43
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 44
MIDlet Guidelines
 MIDlets developed on top of Canvas class will
receive the following notifications:
 Canvas.hideNotify(): When switching to background
 Canvas.showNotify(): When returning to foreground
 MIDP2.0 spec. doesnt offer APIs for MIDlet that
doesnt use the Canvas class facilities
MIDlet State Detection
2006 JavaOneSM
Conference | Session TS-3742 | 45
MIDlet Guidelines
 Switching to background does not pause a
MIDlet by default
 Legacy content handling
 Some MIDlets (e.g., legacy games) will not run
correctly in the background
 A new JADfile property can request that the MIDlet
be paused when switched to background
In the Background, Am I Paused?
2006 JavaOneSM
Conference | Session TS-3742 | 46
MIDlet State Detection
 Most of the games should be suspended in
background
 Player may be inadvertently killed
 Free up resource that arent in use
 No need to continue painting when nobody sees
the results
 Make sure to attract the users attention when
something interesting happens in the
background
How to Behave While Executing in Background?
2006 JavaOneSM
Conference | Session TS-3742 | 47
MIDlet Guidelines
 Return resources when you are done with
them, dont wait for destroyApp()
 Expect and detect failures in resource
acquisition
 Help the users to overcome resource
acquisition failure
 Expect to see new JAD file properties for
resource policy indication (heap size, special
sound policy, etc.)
Resource Awareness
2006 JavaOneSM
Conference | Session TS-3742 | 48
Boot-time MIDlets
 Launch in the background at boot time
 Bring to foreground upon arrival of
incoming event
 Examples:
 MMS, SMS, IM, Mail clients
 Stock, weather, news
2006 JavaOneSM
Conference | Session TS-3742 | 49
Summary
 MVM in the configuration level:
 Isolation Model
 JVM executes in a single native task context
 MVM in the profile level
 Foreground and Background state
 Resource management and policy
 User experience
 Multitasking safety
 MIDlets in MVM environment
2006 JavaOneSM
Conference | Session TS-3742 | 50
Agenda
MVM overview
MVM in the configuration level
MVM in the profile level
 The Foreground and Background state
 Resource management
 Multitasking safety
MIDlets in MVM environment
Q&A
2006 JavaOneSM
Conference | Session TS-3742 | 51
Q&A
2006 JavaOneSM
Conference | Session TS-3742 |
Dancing While Gaming
Multitasking VMs (MVM)
on Real Devices
Jae Hyou Lee Yaniv Shani
Samsung Electronics Sun Microsystems, Inc.
www.samsung.com www.sun.com
TS-3742

More Related Content

Ts 3742

  • 1. 2006 JavaOneSM Conference | Session TS-3742 | Dancing While Gaming Multitasking VMs (MVM) on Real Devices Jae Hyou Lee Yaniv Shani Samsung Electronics Sun Microsystems, Inc. www.samsung.com www.sun.com TS-3742
  • 2. 2006 JavaOneSM Conference | Session TS-3742 | 2 Goal Deeper understanding of Multitasking VM implementation on real devices
  • 3. 2006 JavaOneSM Conference | Session TS-3742 | 3 Project Highlights A joint collaboration between Samsung Electronics and Sun Microsystems MVM deployment is based on Suns JWC1.1.3 Deploying most of the MSA JSRs Tested with hundreds of games and applications from leading content providers
  • 4. 2006 JavaOneSM Conference | Session TS-3742 | 4 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 5. 2006 JavaOneSM Conference | Session TS-3742 | 5 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 6. 2006 JavaOneSM Conference | Session TS-3742 | 6 What Is MVM? Running multiple applications simultaneously Java is always on Favorite applications instantly available MP3 Playing Chatting Gaming
  • 7. 2006 JavaOneSM Conference | Session TS-3742 | 7 MVM Conceptual View Device H/W Operating System Native JVM Task Configuration Level MVM Resource Manager App. Manager AMS JSR JSR JSRJSR Profile Level Multitasking Safety Isolation Model Deployment Guidelines Legacy Content New App States User Experience Resource Policies
  • 8. 2006 JavaOneSM Conference | Session TS-3742 | 8 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 9. 2006 JavaOneSM Conference | Session TS-3742 | 9 Isolates and Tasks Each application runs in its own logical Java Virtual Machine, called an Isolate. Within the JVM, each isolate is represented as a Task. A task consists of one more Java thread of execution.
  • 10. 2006 JavaOneSM Conference | Session TS-3742 | 10 More on Tasks All tasks execute in the same single OS task context All tasks share: Constant data structure Runtime support functions Each task encapsulates non-sharable program state MVM
  • 11. 2006 JavaOneSM Conference | Session TS-3742 | 11 Implementation Details Each task has a separate, private copy of the static variables of all the loaded Java classes Static variables are only global to all threads within a particular task Static Variable class A { public static int count; ... } Task 1 class A { public static int count; ... } task 2 MVM Each task maintains a private copy of count The Class representation is shared
  • 12. 2006 JavaOneSM Conference | Session TS-3742 | 12 Implementation Details Synchronization class A { public static synchronized int open(); } Synchronization has to be task private Threads in one task cannot block threads in another task Task 1 Task 2 MVM A.open() A.open() A.open() A.open() Blocking Threads Across Tasks Isnt Allowed
  • 13. 2006 JavaOneSM Conference | Session TS-3742 | 13 Resource Management The JVM is responsible for CPU time and memory resources in order to ensure that all tasks get their fair share Other resources, such as network bandwidth and communication ports are managed by the profile layer
  • 14. 2006 JavaOneSM Conference | Session TS-3742 | 14 Resource ManagementScheduling Tasks and thread are scheduled by the JVM Fair scheduling algorithm is used for task scheduling in order to prevent one task from taking disproportionate CPU time The Isolate class offers a set of APIs to modify the priority levels for each task ` Task 2 Scheduler MVM Task 1 Active Thread MVM
  • 15. 2006 JavaOneSM Conference | Session TS-3742 | 15 Resource ManagementMemory All tasks allocations are conducted from the same global heap region The virtual machine has a bookkeeping mechanism that accounts for each task total heap memory consumption The JVM injects OutOfMemoryError as needed to inform tasks that heap space has become scarce
  • 16. 2006 JavaOneSM Conference | Session TS-3742 | 16 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 17. 2006 JavaOneSM Conference | Session TS-3742 | 17 New MIDlet State in MVM An application is said to be in the Foreground when: Its displayable controls the display It handles event from the user input mechanism Only one MIDlet can execute in the Foreground at a time Foreground MIDlet
  • 18. 2006 JavaOneSM Conference | Session TS-3742 | 18 New MIDlet State in MVM Background MIDlet An application is in the Background when: Its displayable does not control the display It does not handle the user inputs mechanism Zero or more MIDlets can execute in the Background at a time
  • 19. 2006 JavaOneSM Conference | Session TS-3742 | 19 The Application Manager A resident MIDIet Executed from power on Lists the running applications A fast way to switch between running MIDlets Display background MIDIets alerts
  • 20. 2006 JavaOneSM Conference | Session TS-3742 | 20 Switching a MIDlet to the Background (1/3) Upon a short Hot key press the foreground MIDlet will be placed in the background and main device menu will be displayed Short Hot Key Press Short Hot Key
  • 21. 2006 JavaOneSM Conference | Session TS-3742 | 21 Switching a MIDlet to the Background (2/3) Upon a long Hot key press the foreground MIDlet will be placed in the background and the Application manager dialog will be displayed Long Hot Key Long Hot Key
  • 22. 2006 JavaOneSM Conference | Session TS-3742 | 22 Switching a MIDlet to the Background (3/3) Invoking Display.setCurrent(null) Upon calling setCurrent(null) the MIDlet will be placed in the background and the idle screen of the device will be displayed Display.setCurrent(null)
  • 23. 2006 JavaOneSM Conference | Session TS-3742 | 23 Interrupting the User Background MIDlet calls Display.setCurrent(alert) Background MIDlet tries to access a protected API and a security dialog is prompted Noteworthy event occurred in the background e.g., Incoming IM while playing a game
  • 24. 2006 JavaOneSM Conference | Session TS-3742 | 24 DEMO User Experience Demonstration
  • 25. 2006 JavaOneSM Conference | Session TS-3742 | 25 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 26. 2006 JavaOneSM Conference | Session TS-3742 | 26 Managing Resources In a single-tasking environment, the MIDlet has access to all of the available resources In a multitasking environment, MIDlets have to compete for available resources
  • 27. 2006 JavaOneSM Conference | Session TS-3742 | 27 Managing Resources Mechanisms Reservation Quota Revocation Policies Fixed partition Open for competition Special cases
  • 28. 2006 JavaOneSM Conference | Session TS-3742 | 28 Resource Management Mechanisms A reservation mechanism sets aside a certain amount of a resource for a MIDlet and keeps it available for that MIDlet and that MIDlet alone Reservation
  • 29. 2006 JavaOneSM Conference | Session TS-3742 | 29 Resource Management Mechanisms A quota mechanism permits a MIDlet to allocate up to a certain amount of a resource; if the MIDlet attempts to allocate more resources than its quota, the attempt fails, even if resources are actually available on the system Quota
  • 30. 2006 JavaOneSM Conference | Session TS-3742 | 30 Resource Management Mechanisms The system can revoke a resource from a MIDlet and give it to another MIDlet Resource revocation examples: CPU cycles Display access Audio playback Resource revocation doesnt always have a dramatic effect on the MIDlets execution Revocation
  • 31. 2006 JavaOneSM Conference | Session TS-3742 | 31 Resource Management Policies Initial amount of resources are reserved before MIDlet launch Resource availability validation during MIDlets startup Ensure consistent MIDlet behavior Fixed Partition
  • 32. 2006 JavaOneSM Conference | Session TS-3742 | 32 Resource Management Policies No reservation Resource are acquired and reclaimed at runtime May lead to unpredictable behavior Open for Competition
  • 33. 2006 JavaOneSM Conference | Session TS-3742 | 33 Special Resource Management Policies Only the Foreground can access the LCD display and receive key inputs events The current displayable of a Background MIDlet is still updated Note: vibrate() ,flashBacklight() and tone playing arent honored when invoked from a Background MIDlet LCD Display
  • 34. 2006 JavaOneSM Conference | Session TS-3742 | 34 Sound (1/2) Special Resource Management Policies Foreground MIDlets are assigned physical player that can access the audio device resource Background MIDlets are assigned a logical player that only maintains the audio state Upon foreground switch the player state is changed automatically Logical Player Physical Player 1 Logical Player Physical Player 2 Foreground Switch
  • 35. 2006 JavaOneSM Conference | Session TS-3742 | 35 Special Resource Management Policies Unique JAD file property to lock audio resources Allows a background MIDlet to be audible Useful for media players (e.g., the MP3 player, radio, etc.) Sound (2/2) 1 Logical Player Physical Player 2 Logical Player Physical Player 1 Foreground Switch
  • 36. 2006 JavaOneSM Conference | Session TS-3742 | 36 A Full Resource Policy Matrix Fixed Open Special Memory X X CPU X X File Descriptor X X Socket X X Display X Sound X X Bluetooth X Location X PIM X
  • 37. 2006 JavaOneSM Conference | Session TS-3742 | 37 Guidelines for Resource Policy Selection Resource policy definition relies on the underlying platform capabilities and requirements Fixed partition policy should be used for fundamental resources that are required by the majority of the applications (e.g., memory, file, socket) Open policy should be used resources that are used by specific MIDlets and have limited availability (e.g., Bluetooth, location) Display and sound requires special handling
  • 38. 2006 JavaOneSM Conference | Session TS-3742 | 38 DEMO Resource Policy Demonstration
  • 39. 2006 JavaOneSM Conference | Session TS-3742 | 39 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 40. 2006 JavaOneSM Conference | Session TS-3742 | 40 Multitasking Safety The native JVM task can run native code for any task, hence the code must be made aware of the task on whose behalf it is being called and possibly allocating resources When the task context is established, the code is considered multitasking safe Suns JWC software is multitasking safe
  • 41. 2006 JavaOneSM Conference | Session TS-3742 | 41 Multitasking Safety Implementation Guidelines In some cases a deployment of a profile to MVM environment requires additional development in order that the profile will execute properly Foreground Switch Blocking Threads Across Tasks Isnt Allowed
  • 42. 2006 JavaOneSM Conference | Session TS-3742 | 42 Multitasking Safety At Java level, each task has a separate, private copy of the static variables of all the loaded Java classes This is handled internally by the MVM Native code often has global data Native data is shared across all tasks! Global native data needs to be replicated for each task Held as a field of a Java object Proper handling for singleton depends on whether it is meant be used on a per-task basis (the default behavior for MVM), or by the entire system Static and Global Variable
  • 43. 2006 JavaOneSM Conference | Session TS-3742 | 43 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 44. 2006 JavaOneSM Conference | Session TS-3742 | 44 MIDlet Guidelines MIDlets developed on top of Canvas class will receive the following notifications: Canvas.hideNotify(): When switching to background Canvas.showNotify(): When returning to foreground MIDP2.0 spec. doesnt offer APIs for MIDlet that doesnt use the Canvas class facilities MIDlet State Detection
  • 45. 2006 JavaOneSM Conference | Session TS-3742 | 45 MIDlet Guidelines Switching to background does not pause a MIDlet by default Legacy content handling Some MIDlets (e.g., legacy games) will not run correctly in the background A new JADfile property can request that the MIDlet be paused when switched to background In the Background, Am I Paused?
  • 46. 2006 JavaOneSM Conference | Session TS-3742 | 46 MIDlet State Detection Most of the games should be suspended in background Player may be inadvertently killed Free up resource that arent in use No need to continue painting when nobody sees the results Make sure to attract the users attention when something interesting happens in the background How to Behave While Executing in Background?
  • 47. 2006 JavaOneSM Conference | Session TS-3742 | 47 MIDlet Guidelines Return resources when you are done with them, dont wait for destroyApp() Expect and detect failures in resource acquisition Help the users to overcome resource acquisition failure Expect to see new JAD file properties for resource policy indication (heap size, special sound policy, etc.) Resource Awareness
  • 48. 2006 JavaOneSM Conference | Session TS-3742 | 48 Boot-time MIDlets Launch in the background at boot time Bring to foreground upon arrival of incoming event Examples: MMS, SMS, IM, Mail clients Stock, weather, news
  • 49. 2006 JavaOneSM Conference | Session TS-3742 | 49 Summary MVM in the configuration level: Isolation Model JVM executes in a single native task context MVM in the profile level Foreground and Background state Resource management and policy User experience Multitasking safety MIDlets in MVM environment
  • 50. 2006 JavaOneSM Conference | Session TS-3742 | 50 Agenda MVM overview MVM in the configuration level MVM in the profile level The Foreground and Background state Resource management Multitasking safety MIDlets in MVM environment Q&A
  • 51. 2006 JavaOneSM Conference | Session TS-3742 | 51 Q&A
  • 52. 2006 JavaOneSM Conference | Session TS-3742 | Dancing While Gaming Multitasking VMs (MVM) on Real Devices Jae Hyou Lee Yaniv Shani Samsung Electronics Sun Microsystems, Inc. www.samsung.com www.sun.com TS-3742