java - Is it safe to keep a reference to a thread in a singleton? -


let me give scenario.

say first activity loads up, creates thread, run indefinitely in background.

now, if move activity, assume thread created in main activity continue run.

so, main question - in order manage background thread other activities, safe store reference thread in singleton object?

yes , no. theoretically, have no problem, must not allow references escape.

problems can arise keeping reference in singleton object private, must not pass reference else or allow access else, or can lose control.

secondly, thread created activity must not allow access member variables or allow references them escape.

a book on area "java concurrency in practice" brian goetz


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -