synchronization

MS-SQL Server 2005: Initializing a merge subscription with alternate snapshot location

▼魔方 西西 提交于 2019-12-05 05:14:29
问题 We started some overseas merge replication 1 year ago and everything is going fine till now. My problem is that we have now so much data in our system that any crash on one of the subscriber's servers will be a disaster: reinitialising a subscription the standard way will take days (our connexions are definitely slow, but already very very expensive)! Among the ideas I have been following up are the following: make a copy of the original database, freeze it, send the files by plane to the

When using synchronized(lock), the lock object is prefered to be static or non-static?

风流意气都作罢 提交于 2019-12-05 04:36:05
问题 When using something like this: private final Object lock = new Object() Is there any difference between static and non-static one? Can non-static object lock static method or vice versa? 回答1: If you're using a non-static lock, every instance of the object would have a different lock object, and it would be a potentially more fine grained equivalent of calling: synchronized(this) { } That is to say: you're only locking against other accesses from within the same object. With a static lock,

Are size(), put(), remove(), get() atomic in Java synchronized HashMap?

旧巷老猫 提交于 2019-12-05 04:32:44
I am declaring a Java Map as Map<String, String> map = Collections.synchronizedMap(new HashMap<String, String>()); to deal with the concurrency issues, and synchronizing on the map for all the operations on it. However, I read that synchronization isn't necessary on a synchronizedMap when the operations are atomic. I checked the Java API and the documentation of HashMap doesn't seem to mention which are atomic, so I'm not sure which are. I'm synchronizing on the following calls to the map: map.size() map.put() map.remove() map.get() But if some are atomic, it seems synchronization isn't

Synchronization concerns with a static method in java

南笙酒味 提交于 2019-12-05 04:30:52
问题 Suppose I have a Utility class, public class Utility { private Utility() {} //Don't worry, just doing this as guarantee. public static int stringToInt(String s) { return Integer.parseInt(s); } }; Now, suppose, in a multithreaded application, a thread calls, Utility.stringToInt() method and while the operation enters the method call, another thread calls the same method passing a different s . What happens in this case? Does Java lock a static method? 回答1: There is no issue here. Each thread

Java synchronize in singleton pattern

戏子无情 提交于 2019-12-05 03:26:28
Does the synchronize keyword need to be applied to each method of a class that implements the singleton pattern like this? public class Singleton { private Singleton(){} public synchronized static Singleton getInstance() { if(instance == null) instance = new Singleton (); return instance; } public void DoA(){ } } Since Singletons don't expose a public constructor and the getInstance() method is synchronized, one does not need to synchronize method DoA and any other public methods exposed by the Singleton class. Is this reasoning correct? It's just like any other class. It may or may not need

What is the correct way to prevent reentrancy and ensure a lock is acquired for certain operations?

眉间皱痕 提交于 2019-12-05 03:25:17
I'm designing a base class that, when inherited, will provide business functionality against a context in a multithreaded environment. Each instance may have long-running initialization operations, so I want to make the objects reusable. In order to do so, I need to be able to: Assign a context to one of these objects to allow it to do its work Prevent an object from being assigned a new context while it already has one Prevent certain members from being accessed while the object doesn't have a context Also, each context object can be shared by many worker objects. Is there a correct

Java: Synchronization Utility

淺唱寂寞╮ 提交于 2019-12-05 02:53:14
问题 I am asking this purely to determine the worthwhile-ness of implementing the class in Question ... Do you know of a Java utility class that takes an un-synchronized instance, uses reflection to investigate that instance, and returns the input instance "wrapped" within synchronized calls ? ( ie: A factory which creates a synchronized delegate class for any instance ) 回答1: I like Jon Skeet's answer; it's seeing the forest instead of the trees. But to answer the question: Assuming that the

C++0x atomic template implementation

自作多情 提交于 2019-12-05 02:40:29
I know that similar template exits in Intel's TBB, besides that I can't find any implementation on google or in Boost library. You can find discussions about this feature implementation in boost there : http://lists.boost.org/Archives/boost/2008/11/144803.php > Can the N2427 - C++ Atomic Types and Operations be implemented > without the help of the compiler? No. They don't need to be intrinsics if you can write inline assembler (or separately-compiled assembler for that matter) then you can write the operations themselves directly. You might even be able to use simple C++ (e.g. just plain

Creating a simple Chat application in Python (Sockets)

可紊 提交于 2019-12-05 02:38:15
问题 I'm trying to create a simple chat application using sockets (python). Where a client can send a message to server and server simply broadcast the message to all other clients except the one who has sent it. Client has two threads, which are running forever send : Send simply sends the cleints message to server. receive : Receive the message from the server. Server also has two threads, which are running forever accept_cleint : To accept the incoming connection from the client. broadcast_usr

Synchronizing Git repos across machines without push

只愿长相守 提交于 2019-12-05 02:36:35
问题 I've got three computers which should have the same settings for all their applications. Since all of them have processes running using those settings, I never want to push, instead I'd like for each of them to track the other two, and pull only when I'm logged in. After working a couple of days on this, all the articles I've found seem to assume that you'd want to push to a central repository before pulling from that at the other machines, but that seems like a waste of space and (transfer)