{"record":{"id":"3cf2258d647c1df2","repo":"code4craft/webmagic","slug":"threadnum-should-be-more-than-one","errorCode":null,"errorMessage":"threadNum should be more than one!","messagePattern":"threadNum should be more than one!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java","lineNumber":617,"sourceCode":"\n    /**\n     * Stop when all tasks in the queue are completed and all worker threads are also completed\n     */\n    public void stopWhenComplete(){\n        this.exitWhenComplete = true;\n    }\n\n    /**\n     * start with more than one threads\n     *\n     * @param threadNum threadNum\n     * @return this\n     */\n    public Spider thread(int threadNum) {\n        checkIfRunning();\n        this.threadNum = threadNum;\n        if (threadNum <= 0) {\n            throw new IllegalArgumentException(\"threadNum should be more than one!\");\n        }\n        return this;\n    }\n\n    /**\n     * start with more than one threads\n     *\n     * @param executorService executorService to run the spider\n     * @param threadNum threadNum\n     * @return this\n     */\n    public Spider thread(ExecutorService executorService, int threadNum) {\n        checkIfRunning();\n        this.threadNum = threadNum;\n        if (threadNum <= 0) {\n            throw new IllegalArgumentException(\"threadNum should be more than one!\");\n        }\n        this.executorService = executorService;","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/code4craft/webmagic/blob/67816a19d68a4fec4657bf1336227e046e251df2/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java#L599-L635","documentation":"Thrown by Spider.thread(int) when the requested worker-thread count is zero or negative. It is a generic validation guard on the caller-supplied threadNum parameter: the value must be at least 1 for the spider to spawn workers, so any non-positive input passed to thread() triggers this IllegalArgumentException immediately, before threadNum is applied.","triggerScenarios":"Calling spider.thread(0) or spider.thread(-1) before running; computing the thread count from a config/property that defaults to 0.","commonSituations":"Loading thread count from a properties/yaml file that is missing or empty and parsed as 0; passing an uninitialized int field.","solutions":["Pass a threadNum of at least 1","Validate/parse the config value before calling thread() and default to 1 when invalid","Check the source of the value for typos or missing keys"],"exampleFix":"// before\nint n = Integer.parseInt(props.getProperty(\"spider.threads\", \"0\"));\nspider.thread(n);\n// after\nint n = Math.max(1, Integer.parseInt(props.getProperty(\"spider.threads\", \"1\")));\nspider.thread(n);","handlingStrategy":"validation","validationCode":"int n = Integer.parseInt(props.getProperty(\"spider.threads\", \"1\")); if (n <= 0) n = 1; spider.thread(n);","typeGuard":null,"tryCatchPattern":"try { spider.thread(n); } catch (IllegalArgumentException e) { spider.thread(1); }","preventionTips":["Validate config-derived integers before use","Default thread counts to 1 when missing","Never pass raw unparsed strings"],"tags":["configuration","argument-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"67816a19d68a4fec4657bf1336227e046e251df2","analyzedAt":"2026-09-08T11:15:28.425Z","contentChangedAt":"2026-09-08T11:15:28.425Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}