# Calling Compiled Queries from an Application

This section does not apply to code generated with the `-servlet` option.

When a query is compiled, as well as having a `main` method allowing invocation from the operating system command line, it will also have a `run()` method allowing invocation from a Java application. This takes two parameters: a JAXP `Result` object to define the destination of the query output, and an `outputProperties` value to define serialization properties.

A query compiled in this way is not thread-safe. A new instance of the generated class should be created in each thread. Within a thread, the object is serially reusable.

Parameters to the query may be supplied using the method `setExternalVariable`. This accepts the name of the variable in Clark notation ({uri}local), and the value as an instance of Saxon's `ValueRepresentation` class. Most commonly this will be a `StringValue`, an `Int64Value`, or a `BooleanValue`.

Next