Here you can find the source of close()
public static void close()
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { private static Map<Long, Scanner> map = new HashMap<>(); public static void close() { Scanner keyboardScanner = getThreadScanner(); if (keyboardScanner != null) { keyboardScanner.close();/*from w w w . ja v a 2 s .c om*/ keyboardScanner = null; } } private static Scanner getThreadScanner() { long threadId = Thread.currentThread().getId(); Scanner keyboardScanner = map.get(threadId); return keyboardScanner; } }