synchronization

How can I ensure that an overridden method is synchronized

我只是一个虾纸丫 提交于 2019-12-02 21:16:56
I have a class of common code that is thread safe. One of the methods in that class is abstract and needs to be overridden for different implementations. I need to ensure or at least flag to other developers that all implementations of this method need to be thread-safe. What is the best way to do this? Is there a keyword or annotation to this effect? I have already tried abstract synchronized but that combination of keywords is not allowed. You can't do it directly. One thing you can do is have the method be concrete, but invoke an abstract method: public synchronized final void foo() { doFoo

iCloud + Core Data today (10th july 2015)

久未见 提交于 2019-12-02 21:11:08
Some years ago Apple released the iCloud sync of Core Data apps. Then I released an app for iPad / iPhone / MAC with a shared model using the new Apple mechanism. Things have not gone as expected. The sync mechanism sometimes doesn't work. For example, the last months, in my case, rarely the sync ends well through my 3 devices. Uploading objects in general works fine. But the download process of new or deleted objects normaly crash. Apple released some time ago a way to force the devices to redownload ALL the objects of the model (NSPersistentStoreRebuildFromUbiquitousContentOption) that

Java RMI and synchronized methods

三世轮回 提交于 2019-12-02 20:44:01
I'm studying the book "Distributed Systems" (by Tanenbaum & Van Steen) and they say something that seems to conflict to what seems to be instead thought by many on Java RMI and synchronized methods. What I thought is that using a synchronized method on a Remote Object implementation (so the real implementation running at the server) concurrent execution of that method is prevented even when the calls to that method are from different clients machines (calling the method via a Proxy... aka a Stub). I've seen that a lot of people have the same opinion, look here for example: Java RMI and Thread

What is the use of Collections.synchronizedList() method? It doesn't seem to synchronize the list

眉间皱痕 提交于 2019-12-02 20:33:25
I am trying to add String values to an ArrayList using two threads. What I want is that while one thread is adding the values the other thread should not interfere so I have used the Collections.synchronizedList method. But it appears that if I don't explicitly synchronize on an object the adding is done in an unsynchronized way. Without explicit synchronized block: public class SynTest { public static void main(String []args){ final List<String> list=new ArrayList<String>(); final List<String> synList=Collections.synchronizedList(list); final Object o=new Object(); Thread tOne=new Thread(new

DB transaction or Java DAO's method synchronization?

萝らか妹 提交于 2019-12-02 20:17:46
问题 I have Java-based web server, and I also have DAO singleton object with method, whose SQL operations' logic must be synchronized in some way in order to guarantee data integrity (method can be accessed from several Java threads simultaneously). I was wondering to know whether DB transaction wrapping (serializable level) is better than DAO's method explicit synchronization in server side? 回答1: Yes, using transactions is better. With synchronizing in your code, locking on the class, the scope

Concurrent File write between processes

限于喜欢 提交于 2019-12-02 20:04:43
问题 I need to write log data into a single file from different processes. I am using Windows Mutex which needs Common Language Runtime support for it. Mutex^ m = gcnew Mutex( false,"MyMutex" ); m->WaitOne(); //... File Open and Write .. m->ReleaseMutex() Do I really need to change from C++ to C++/CLI for synchronization? It is ok if the atomic is not used. But I need to know whether using this Mutex will slow down the performance compared to local mutex. 回答1: Adding CLR support to your C++

On XP, best way to synchronize files and folders [closed]

女生的网名这么多〃 提交于 2019-12-02 19:48:55
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. I'm using SyncToy 1.4 and it would be fine for what I need except that: It can't handle the assigned drive letter changing between systems (e.g. syncing a USB drive), it leaves its own (hidden) files in the folders being synched (is this a limitation of the OS/FS?), it recreates empty folders for ones that have been deleted, it syncs new sub folders in folders that have been unselected from syncing and sometimes finds

What is Test-and-Set used for?

好久不见. 提交于 2019-12-02 19:36:11
After reading the Test-and-Set Wikipedia entry , I am still left with the question "What would a Test-and-Set be used for?" I realize that you can use it to implement Mutex (as described in wikipedia), but what other uses does it have? moonshadow You use it any time you want to write data to memory after doing some work and make sure another thread hasn't overwritten the destination since you started. A lot of lock/mutex-free algorithms take this form. A good example is "increment." Say two threads execute a = a + 1 . Say a starts with the value 100 . If both threads are running at the same

Difference between event object and condition variable

假如想象 提交于 2019-12-02 19:33:54
What is the difference between event objects and condition variables? I am asking in context of WIN32 API. Event objects are kernel-level objects. They can be shared across process boundaries, and are supported on all Windows OS versions. They can be used as their own standalone locks to shared resources, if desired. Since they are kernel objects, the OS has limitations on the number of available events that can be allocated at a time. Condition Variables are user-level objects. They cannot be shared across process boundaries, and are only supported on Vista/2008 and later. They do not act as

Java's equivalent to .Net's AutoResetEvent?

橙三吉。 提交于 2019-12-02 19:19:05
What should I use to get semantics equivalent to AutoResetEvent in Java? (See this question for ManualResetEvent). @user249654's answer looked promising. I added some unit tests to verify it, and indeed it works as expected. I also added an overload of waitOne that takes a timeout. The code is here in case anyone else finds it useful: Unit Test import org.junit.Assert; import org.junit.Test; import static java.lang.System.currentTimeMillis; /** * @author Drew Noakes http://drewnoakes.com */ public class AutoResetEventTest { @Test public void synchronisesProperly() throws InterruptedException {