synchronization

Android SyncAdapter Callback

匆匆过客 提交于 2019-12-05 20:38:25
问题 I have implemented a SyncAdapter, AccountManager and private ContentProvider along the lines of the SimpleSyncAdapter sample project in the SDK. It is all working well. Now I want to show a message to the user when new rows have been downloaded from the remote server that have a specific flag set. I need a callback from the SyncAdapter when a Sync has finished so I can do the query and display the message from an activity. I have seen a few questions on StackOverflow discussing this but none

C# multiple sources, different threads, one event handler

ε祈祈猫儿з 提交于 2019-12-05 20:14:05
I need somebody with high skills in threading and event raising. I have an abstract class A and two concrete classes C1 , C2 (e.g plugins). Since I need them to communicate between each other, like "plugin-application" "plugin-plugin" communication, I have a method ExecuteCommand in the abstract class which should accomplish this. This function raises an event to the application in order to process a certain command and return the result (e.g if one plugin needs data from the app it calls ExecuteCommand from the base and waits for the result which comes with the event handler processed on the

Locking HttpRuntime.Cache for lazy loading

寵の児 提交于 2019-12-05 20:04:25
We have a website running .NET 2.0 and have started using the ASP.Net HttpRuntime.Cache to store the results of frequent data lookups to cut down our database access. Snippet: lock (locker) { if (HttpRuntime.Cache[cacheKey] == null) { HttpRuntime.Cache.Insert(cacheKey, GetSomeDataToCache(), null, DateTime.Today.AddDays(1), Cache.NoSlidingExpiration); } return ((SomeData)HttpRuntime.Cache[cacheKey]).Copy(); } We are pessimistically locking whenever we want to look at the cache. However, I've seen various blogs posted around the web suggesting you lock after you check the cache value instead, to

What do the terms synchronized and thread-safe mean? [closed]

[亡魂溺海] 提交于 2019-12-05 19:59:22
I've been watching a lot of videos on data structures, and these terms are always being mentioned: synchronized/not synchronized and thread-safe/not thread-safe . Can someone explain to me in simple words what synchronized and thread-safe mean in Java? What is sync and what is thread ? A thread is an execution path of a program. A single threaded program will only have one thread and so this problem doesn't arise. Virtually all GUI programs have multiple execution path and hence threads - one for processing the display of the GUI and handing user input, others for actually performing the

Best way for waiting for callback to finish

扶醉桌前 提交于 2019-12-05 18:49:30
问题 In the code below, main() function is calling request() function which inter call th_request_async() function which mm_th_done_cb(). What will be the best and efficient way to proceed in main only after the mm_th_done_cb() is executed. DUMMY CODE int mm_th_done_cb(int error_code, th_result_s* th_result, void* user_data) { return 0; } void request() { th_request_s MyItemInfo; strncpy(MyItemInfo.origin_path, szUrl, 1024+1); MyItemInfo.orientation = 0; MyItemInfo.func = mm_th_done_cb; MyItemInfo

Java happend before thread start

房东的猫 提交于 2019-12-05 18:43:34
I read somewhere that starting a thread has some special effect on the happend before relationship. Now I'm not sure if my code gurantees the happend before relationship, so please enlighten me. I have a Dispatcher thread and a Worker class implementing the Runnable interface. The Dispatcher thread creates a new instance of the Worker and fills a LinkedList in the Worker instance through the add method with elements. Then the Dispatcher hands the Worker instance to a ExecutorService via the execute method. Then the run method in the Worker class starts accessing and removing stuff from the

Silverlight HttpWebRequest syncronous call

浪子不回头ぞ 提交于 2019-12-05 18:11:05
In my silverlight app I do a file upload. I break the file into chunks and then I upload each chunk. The problem is that I want to use the HttpWebRequest synchronously. My propblem is to ensure that all request are ok and to catch exceptions. Is that possible in Silverlight? I would like sopmething like: while(chunk) { try{ HttpWebRequest req = ... req.BeginGetRequestStream(new AsyncCallback(WriteCallback), req); //add data into request stream req.BeginGetResponseStream(new AsyncCallback(ReadCallback), req); //parse the response chunk = new Chunk(); }catch(Exception ex) {...} } Can you give me

java and synchronization

丶灬走出姿态 提交于 2019-12-05 17:43:09
I am preparing for the SCJP exam and I am having trouble with fully understanding synchronization. At line 6, I have read that the thread running in main needs a lock on 'b'. Why does it need a lock on this object? My understanding is that a synchronized block of code is a protected area that only one thread can be in at any time? Moving on,the thread in main releases this lock and waits for the the thread in 'b to complete its run method. The thread in 'b' is then meant to notify the thread in main that it has completed. However, it does not look like it is notifying any specific thread here.

Ldap error code 32

心已入冬 提交于 2019-12-05 17:33:29
问题 I'm trying to synchronize OpenLDAP and Active directory together. To do so I'm using a program called LSC-Project which is specified to do this sort of thing. I have configured the program the best I can however I can't find a way to shake off the following error: javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID- 031001CD, problem 2001 (NO_OBJECT), data 0, best match of: 'DC=domname,DC=com' ]; remaining name 'uid=user1,ou=Users' May 09 15:19:25 - ERROR -

Using AtomicInteger as a static shared counter

巧了我就是萌 提交于 2019-12-05 17:19:31
In an effort to learn about synchronization via Java, I'm just messing around with some simple things like creating a counter shared between threads. The problem I've run into is that I can't figure out how to print the counter sequentially 100% of the time. int counterValue = this.counter.incrementAndGet(); System.out.println(this.threadName + ": " + counterValue); The above increments the AtomicInteger counter , gets the new value, and prints it to the console identified by the thread name that is responsible for that update. The problem occurs when it appears that the incrementAndGet()