प्रेरणाक्या मैं समवर्ती धागे से XMPPConnection.sendPacket का आह्वान कर सकता हूं?
मैं अतिरिक्त आंखें चाहते पुष्टि करने के लिए कि मैं इस विधि XMPPConnection.sendPacket ( पैकेट) समवर्ती कॉल करने के लिए कर रहा हूँ। मेरे वर्तमान कोड के लिए, मैं एक धारावाहिक फैशन में कॉलबेल की सूची (अधिकतम 3) का आह्वान कर रहा हूं। प्रत्येक कॉल योग्य XMPPConnection के एक टुकड़े पर XMPP पैकेट भेजता/प्राप्त करता है। मैं एकाधिक कॉलको कताई करके इन कॉलबल्स को समानांतर करने की योजना बना रहा हूं प्रत्येक कॉल करने योग्य सिंक्रनाइज़ेशन के बिना साझा XMPPConnection पर sendPacket को आमंत्रित करेगा।
XMPPConnection
class XMPPConnection
{
private boolean connected = false;
public boolean isConnected()
{
return connected;
}
PacketWriter packetWriter;
public void sendPacket(Packet packet)
{
if (!isConnected())
throw new IllegalStateException("Not connected to server.");
if (packet == null)
throw new NullPointerException("Packet is null.");
packetWriter.sendPacket(packet);
}
}
PacketWriter
class PacketWriter
{
public void sendPacket(Packet packet)
{
if (!done) {
// Invoke interceptors for the new packet
// that is about to be sent. Interceptors
// may modify the content of the packet.
processInterceptors(packet);
try {
queue.put(packet);
}
catch (InterruptedException ie) {
ie.printStackTrace();
return;
}
synchronized (queue) {
queue.notifyAll();
}
// Process packet writer listeners. Note that we're
// using the sending thread so it's expected that
// listeners are fast.
processListeners(packet);
}
protected PacketWriter(XMPPConnection connection)
{
this.queue = new ArrayBlockingQueue<Packet>(500, true);
this.connection = connection;
init();
}
}
मैं क्या निष्कर्ष निकाल
के बाद से PacketWriter एक BlockingQueue उपयोग कर रहा है, वहाँ आह्वान करने के लिए मेरा इरादा के साथ कोई समस्या नहीं है से एकाधिक धागे से एनडी पैकेट। क्या मैं सही हूँ ?