login about faq

Question from User:

I am making a JAVA based web app and the app spawns several threads to handle incoming requests. I use crypt2, and every time i use it, I create another new instance of the object. However, it has come to my mind that maybe i can use only one instance of crypt2 as a singleton and use it from various threads.

I believe that all chlikat products are thread safe aren't they?

Is this good idea or should i just stick to the method with spawn own chilkat instance for each threads.

asked Apr 21 at 10:09

chilkat's gravatar image

chilkat ♦♦

Chilkat is thread safe, and this means that if two threads are trying to simultaneously call a method on a shared object instance, then one will gain access first, and the other thread will wait until the call in the 1st thread completes. Even though the classes are thread-safe, it would likely be better for performance to use a separate object instance for each thread.

Note: For the Socket class, it makes sense that an app would want one thread to be reading while the other is writing. If Chilkat behaves as described above, then this could never happen. There is a solution, and that is to use the CloneSocket method so that your app has two instances of the Socket object. Now one thread can read using instance A, while the other thread can write using instance B (both instances actually use the same underlying socket (TLS/TCP) and internally the thread-safety for the underlying socket is finer-grained). See http://www.chilkatforum.com/questions/7150/socket-is-locked-internally-while-waiting-for-some-data-and-we-are-not-able-to-send-data-at-the-same-time-from-another-thread


answered Apr 21 at 10:14

chilkat's gravatar image

chilkat ♦♦

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Apr 21 at 10:09

Seen: 233 times

Last updated: Apr 21 at 10:14

powered by OSQA