Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 69
Registered: ‎07-30-2009
My Device: Not Specified

Strange issue in socket connection

Hi all,


               When i try to push different data using  multiple threads simultaneously  in  a single socket connection .


For Eg: 

           Thread 1 Sends: message$uniID&Data=hi

           Thread 2 Sends: message$uniID&Data=hello



I found the data gets mingled  in our server some cases





My code is


public void senddata(String data) {

try {
lastpacket = 0;
msg += data;
boolean isremaining = true;
String resp = "";
int sendLength = 0;
while (isremaining) {
packets = msg.substring(lastpacket * 1024);
if (packets.length() > 1024) {
resp = packets;
sendLength = 1024;
} else if (packets.length() > 0 && packets.length() <= 1024) {
lastpacket = 0;
resp = packets;
sendLength = resp.length();
msg = "";

String d = "";
try {
d = resp.substring(0, sendLength);
_outputStream.write(resp, 0, sendLength);

print("Flused -\n" + d);

} catch (Exception ex) {
print("writing err-" + ex.toString());
isremaining = false;
if (msg.length() == 0) {
isremaining = false;


} catch (Exception e) {
isremaining = false;







Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Strange issue in socket connection

That looks like "expected behavior" to me, not a "Strange issue". Smiley Happy


Whenever you have multiple threads sharing a single object, access to this object must be synchronized.


See the java keyword "synchronized"