2015-08-13 23:54:40 +02:00
---
layout: pattern
title: Callback
folder: callback
2015-08-15 18:03:05 +02:00
permalink: /patterns/callback/
2016-08-30 15:10:34 +02:00
pumlid: FSVB4S8m30N0Lg20M7UwUL4qYOciUFGXxSE9s-wp6sjjKgwF8tF6YyXnjxtdKMk5E5-MOjdu6jIrRYIStlXWsIJwRij4fhW53SGFn51TmIT9yZ-jVBHPGxy0
2015-08-20 21:40:07 +02:00
categories: Other
2015-12-28 15:52:44 +02:00
tags:
- Java
- Difficulty-Beginner
- Functional
- Idiom
2015-08-13 23:54:40 +02:00
---
2016-01-03 21:14:30 +01:00
## Intent
Callback is a piece of executable code that is passed as an
2015-08-13 23:54:40 +02:00
argument to other code, which is expected to call back (execute) the argument
at some convenient time.

2016-01-03 21:14:30 +01:00
## Applicability
Use the Callback pattern when
2015-08-13 23:54:40 +02:00
* when some arbitrary synchronous or asynchronous action must be performed after execution of some defined activity.
2016-01-03 21:14:30 +01:00
## Real world examples
2015-08-13 23:54:40 +02:00
2016-04-15 08:21:29 +03:00
* [CyclicBarrier ](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html#CyclicBarrier%28int,%20java.lang.Runnable%29 ) constructor can accept callback that will be triggered every time when barrier is tripped.