Skip to content

Instantly share code, notes, and snippets.

7.731s][info][gc,stats ] === Garbage Collection Statistics =======================================================================================================================
[7.731s][info][gc,stats ] Last 10s Last 10m Last 10h Total
[7.731s][info][gc,stats ] Avg / Max Avg / Max Avg / Max Avg / Max
[7.731s][info][gc,stats ] Contention: Mark Segment Reset Contention 23 / 164 23 / 164 23 / 164 23 / 164 ops/s
[7.731s][info][gc,stats ] Contention: Mark SeqNum Reset Contention 0 / 2 0 / 2 0 / 2 0 / 2 ops/s
[7.731s][info][gc,stats ] Critical: Allocation Stall 0 / 0 0 / 0
-Xlog Usage: -Xlog[:[selections][:[output][:[decorators][:output-options]]]]
where 'selections' are combinations of tags and levels of the form tag1[+tag2...][*][=level][,...]
NOTE: Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched.
Available log levels:
off, trace, debug, info, warning, error
Available log decorators:
time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname (hn), pid (p), tid (ti), level (l), tags (tg)
Decorators can also be specified as 'none' for no decoration.
public class TestUserService {
@Test
public void testFindUserExisting() {
Map<Long, User> users = new HashMap<>();
users.put(100L, new User(100L, "John", "Doe"));
UserService service = new UserService(users, null);
User returnedUser = service.findUser(100L);
public class UserController {
private UserService service;
public UserController(UserService service) {
this.service = service;
}
...
}
@ExceptionHandler(ClientException.class)
public ResponseEntity<String> clientError(ClientException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
@ExceptionHandler(NotFoundException.class)
public ResponseEntity<String> resourceNotFound(NotFoundException e) {
return ResponseEntity.notFound().build();
}
@Service
public class UserService {
private List<User> users = new ArrayList<>();
private static final Random ID_GENERATOR = new Random();
public User findUser(long userId) {
for(User user : users) {
if(user.getId().equals(Long.valueOf(userId))) {
return user;
@RestController
@RequestMapping("/api/v1/users")
public class UserController {
private UserService service;
public UserController(UserService service) {
this.service = service;
}
@GetMapping("/header")
public String welcomeUser(@RequestHeader String user) {
return String.format("Welcome %s!", user);
}
@GetMapping("/name")
public String helloQueryMessage(@RequestParam String firstName, @RequestParam String lastName) {
return String.format("Hello %s %s!", firstName, lastName);
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>