我尝试了一个简单的应用程序,但在运行时我得到non-sequential
输出,但我想要sequential
输出。每次我运行程序System.err.println()
以不同的顺序执行。有什么办法解决这个请帮忙。
这是源代码的一部分 -
private static final BookDAO bookDao = (BookDAO) new BookDAOImpl();
public static void main(String[] args) {
System.err.println("Listing all Books:");
findAllBooks();
System.out.println();
System.err.println("Search book by keyword in book title : Groovy:");
searchBooks("Groovy");
System.out.println();
System.err.println("Search book by keyword in author's name : Josh:");
searchBooks("Josh");
}
private static void findAllBooks() {
List<Books> book = bookDao.findAllBooks();
for (Books books : book) {
System.out.println(books);
}
}
private static void searchBooks(String keyWord) {
List<Books> books = bookDao.searchBooksByKeyword(keyWord);
for (Books book : books) {
System.out.println(book);
}
}
输出应该是这样的 -
Listing all Books:
Book - Id: 1, Book Title: Practical Clojure
Book - Id: 2, Book Title: Beginning Groovy, Gr
Book - Id: 3, Book Title: Definitive Guide to
Book - Id: 4, Book Title: Groovy and Grails Re
Book - Id: 5, Book Title: Modern Java Web Deve
Book - Id: 6, Book Title: Java 7 Recipes
Book - Id: 7, Book Title: Java EE 7 Recipes
Book - Id: 8, Book Title: Beginning Java 7
Book - Id: 9, Book Title: Pro Java 7 NIO.2
Book - Id: 10, Book Title: Java 7 for Absolute
Book - Id: 11, Book Title: Oracle Certified Jav
Book - Id: 12, Book Title: Beginning Scala
Search book by keyword in book title : Groovy:
Book - Id: 2, Book Title: Beginning Groovy, Gr
Book - Id: 4, Book Title: Groovy and Grails Re
Search book by keyword in author's name : Josh:
Book - Id: 6, Book Title: Java 7 Recipes
Book - Id: 7, Book Title: Java EE 7 Recipes
我得到了这样的输出 -