मैं एंड्रॉइड एप्लिकेशन के लिए कस्टम लॉगर बनाना चाहता हूं। लॉगिंग एक अलग थ्रेड में किया जाना चाहिए क्योंकि एप्लिकेशन बहुत सारी जानकारी उत्पन्न करता है। मैं एंड्रॉइड लॉग का उपयोग नहीं करना चाहता क्योंकि मुझे एक विशिष्ट प्रारूप में लॉग लिखने की ज़रूरत है। एक से अधिक थ्रेड एक ही समय में लॉग फ़ाइल के लिए लिख दिया जाएगा, तो मैं एक कतार का इस्तेमाल किया है लॉग संदेशोंएंड्रॉइड एप्लिकेशन के लिए कस्टम लॉगिंग
यहाँ रखने के लिए मैं
Queue<LogEntry> logQueue = new LinkedBlockingQueue<LogEntry>();
LogWritterThread logWritterThread = new LogWritterThread();
// to queue the log messages
public void QueueLogEntry(String message)
{
LogEntry le = new LogEntry(message);
{
logQueue.add(le);
logQueue.notifyAll();
}
logWritterThread.start();
}
class LogWritterThread extends Thread
{
public void run()
{
try
{
while(true)
{
//thread waits until there are any logs to write in the queue
if(logQueue.peek() == null)
synchronized(logQueue){
logQueue.wait();
}
if(logQueue.peek() != null)
{
LogEntry logEntry;
synchronized(logQueue){
logEntry = logQueue.poll();
}
// write the message to file
}
if(Thread.interrupted())
break;
}
}
catch (InterruptedException e)
{
}
}
}
कोई बात इस के साथ गलत है कि कोड है कोड? या एक बेहतर तरीका एक प्रवेश कतार बनाने के लिए
धन्यवाद, अनुज
मदद के लिए धन्यवाद चिह्नित नहीं कर सकते .... –