I'm using jedis client to interact with the Redis database. I'm using the code like the following as mentioned here in the docs. I'm reusing the jedisPooled repeatedly in various places to add keys and values. I want to know whether the following method is thread-safe or not.
import redis.clients.jedis.JedisPooled
val jedisPooled = JedisPooled("localhost", 6379);
jedisPooled.set("enabled","true)
It is mentioned here that connection pools are thread-safe. But I encounter exceptions like
java.net.SocketException as mentioned here. I would appreciate it very much if someone could tell me what am I doing wrong?
JedisPooled is thread safe (as mentioned in the doc you linked).
java.net.SocketException is not due to thread safety issue. Look into the error on its own like the question you linked.
Related
I'm writing yarn applications and I wonder if these interfaces are thread-safe. When I look up their api, I cannot find any message of it.
After reading the source code, I have found that its api is thread-safe since it has synchronized symbol.
What is the main use of NSAssert Vs. NSException. What is more recommended and when?
Assertions are generally used during development only and are compiled-out of the app when in release mode (this is controlled by NS_BLOCK_ASSERTIONS). Exceptions, on the other hand, can be used at all times.
When an exception is thrown, it travels back up the call chain, until it is either caught (and reported, ignored, or another exception is thrown) or it reaches the top, in which case it will cause the app to crash. It can be considered part of the contract of a class method and needs to be documented so the caller can handle this correctly.
Assertions are really a runtime developer check that ensure that something (generally a instance variable) is in a certain state and if it's not then abort() in order to bring the issue to the developers attention. It's a developer sanity check to check that something is in the state the developer expects it to be.
Assertions are used to find things that should never happen under any circumstances if your code is working the way you think it should be. If they are happening, there is a bug in your code and you want to know about it, at least if it happens during testing. (Most people turn off assertions in released code.)
In contrast, exceptions are used to find things that have gone wrong over which you have no control. For example, if your application is dependent on a database server and that database server is unavailable, that might raise an exception in your code. (Do not make the mistake of using exceptions for things like user input validation. If it's regular program flow--the user forgot to enter a field or whatever--that's not an exception. Exceptions should be exceptional.)
I'm a fresh man to OMG DDS and I tried to run the example GreetingPublishingApp. I don't know what should I do.
DomainParticipantFactory factory =
DomainParticipantFactory.getInstance(Bootstrap.createInstance());
DomainParticipant dp = factory.createParticipant();
It looks like you are trying to use the new Java5 API, which is still in-progress. The API alone will not help as it is just a facade to an underlying implementation. As far as I know no current implementations support the new API, as it is not yet finished.
Regarding the error message: the intent is to put the class of the concrete implementation into the org.omg.dds.serviceClassName system property.
While doing GetComponentParts I am getting following error, to be specific it reporoduces while i do import in continuous loop while handling multiple messages in my WCF application
The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) The composition failed because it did not complete within '100' iterations. This is most likely caused by a cycle in the dependency graph of a part which is marked with a non-shared creation policy.
One more thing I cant locate CompositionException.Errors to find the root cause.
Please suggest what workaround possible, as i am not getting a single thread on the net suggesting any way...
Many Thanks
Since this is working most of the time, it is probably a threading issue which is corrupting MEF's internal state and causing this error.
When using a CompositionContainer from multiple threads, you need to create it with the isThreadSafe parameter set to true, and avoid calling methods which modify what is available - such as Compose, ComposeParts, or AddExportedValue.
Methods which are safe to call are the GetExport and SatisfyImports methods.
I've been (happily) using Ninject for a while now with some basic scenarios, and would like to give it control of my logging. I noted the existence of the Ninject.Extensions.Logging namespace, and would like to use it, but I'm running into two issues:
I want the logger to be initialized with the type of the class running it (as if I ran LogManager.GetLogger with the GetCurrentMethod().DeclaringType).
I want to be able to easily mock, or "nullify" the logger for unit testing (i.e I don't want to have the logger work), without running into NullReferenceExceptions for not initializing the logger.
Now, I know there are some questions (and even answers) around here, but I couldn't seem to find any that pointed me in the right direction.
I'll appreciate any help (even a "you bone-head" it's here! Linking to something I should have noticed).
This is the default behavior of the extension
Don't use Ninject to create the object under test in your unit tests. Create an instance manually and pass what ever you want for the logger.
Best you have a look at the unittests. https://github.com/ninject/ninject.extensions.logging/blob/master/src/Ninject.Extensions.Logging.Tests/Infrastructure/CommonTests.cs