Implementation:A616567126 GPT WEB JAVA InitUtil
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Resource_Management, API_Management |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for initializing application state at startup and managing the GPT API key pool, provided by the Spring framework.
Description
The InitUtil class is a @Component that runs initialization logic via @PostConstruct. At startup, it:
- Loads all active GPT keys (state=0) from the database into a static
ConcurrentHashMap - Caches
SysConfigandPayConfigin Redis for fast access - Sets JVM proxy properties if configured
- Loads Discord account configurations if MJ is enabled
The key pool is accessed via static methods: getRandomKey(type) filters by model type, shuffles, and returns a random key. add(), removeKey(), and getAllKey() manage the pool.
Usage
Import this utility when you need to:
- Select a random GPT API key for a specific model type
- Access the in-memory GPT key cache
- Understand startup initialization (config caching, key pool loading)
Code Reference
Source Location
- Repository: GPT-WEB-JAVA
- File: src/main/java/com/intelligent/bot/utils/sys/InitUtil.java
Signature
@Component
public class InitUtil {
@PostConstruct
public void init();
public static void add(String str, GptKey gptKey);
public static Collection<GptKey> getAllKey();
public static synchronized String getRandomKey(Integer type);
public static void removeKey(final String key);
}
Import
import com.intelligent.bot.utils.sys.InitUtil;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| type | Integer | Yes | GPT model type for key filtering (3, 4, 5) |
Outputs
| Name | Type | Description |
|---|---|---|
| getRandomKey returns | String | Randomly selected GPT API key; throws E if none available |
| getAllKey returns | Collection<GptKey> | All cached keys |
Usage Examples
Selecting a GPT Key
// In GptController.gptChat()
String gptKey = InitUtil.getRandomKey(req.getType());
// Type 3 → GPT-3.5 key, Type 4 → GPT-4 key, Type 5 → Vision key
// Usage count incremented asynchronously
Adding a Key at Runtime
InitUtil.add(gptKey.getId().toString(), gptKey);
// Adds to ConcurrentHashMap if not already present
Related Pages
Implements Principle
Requires Environment
- Environment:A616567126_GPT_WEB_JAVA_Spring_Boot_Runtime
- Environment:A616567126_GPT_WEB_JAVA_MySQL_Database
- Environment:A616567126_GPT_WEB_JAVA_Redis_Cache
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment