The Session Archive (会话存档) SDK has been refactored to use a ThreadLocal pattern. Instead of a shared SDK with reference counting, each thread now maintains its own independent SDK instance. This ensures thread safety and allows multiple calls within the same thread (e.g., fetching records, decrypting data, and downloading media) to reuse the same SDK instance without repeated initialization.
Key Lifecycle Rules:
- Lazy Initialization: The SDK is initialized automatically on the first call within a thread.
- Thread-Bound: The SDK instance is tied to the current thread.
- Manual Cleanup Required: Because the SDK uses native resources, you must explicitly release the SDK when a thread's task is finished to prevent native memory and connection leaks.
// Typical usage pattern
WxCpMsgAuditService msgAuditService = wxCpService.getMsgAuditService();
try {
// Multiple calls reuse the same SDK instance within this thread
List<WxCpChatDatas.WxCpChatData> records = msgAuditService.getChatRecords(seq, 100L, null, null, 30L);
for (WxCpChatDatas.WxCpChatData record : records) {
WxCpChatModel model = msgAuditService.getDecryptChatData(record, 2);
// ...
}
} finally {
// CRITICAL: Always call this in a finally block to release native resources
msgAuditService.closeThreadLocalSdk();
}