Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA InitUtil

From Leeroopedia
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:

  1. Loads all active GPT keys (state=0) from the database into a static ConcurrentHashMap
  2. Caches SysConfig and PayConfig in Redis for fast access
  3. Sets JVM proxy properties if configured
  4. 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

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment