public static void testBackground() {
	Xots.getService().submit(new UserOutput());
}

@Tasklet(session = Tasklet.Session.CLONE, context = Tasklet.Context.XSPSCOPED)
private static class UserOutput extends AbstractXotsXspRunnable {

	public UserOutput() {

    }

    public void run() {
    	try {
        	if (getContext().getSessionScope().containsKey("javaXotsOutput")) {
            	getContext().getSessionScope().put("javaXotsOutput", null);
            }
            StringBuilder sb = new StringBuilder();
            Database currDb = Factory.getSession(SessionType.CURRENT).getCurrentDatabase();
            View states = currDb.getView("AllStates");
            View people = currDb.getView("AllContactsByState");
            for (Document state : states.getAllDocuments()) {
            	String name = state.getItemValueString("Name");
                String key = state.getItemValueString("Key");
                sb.append("Processing " + name + "....<br/>");
                StringBuilder names = new StringBuilder();
                for (Document doc : people.getAllDocumentsByKey(key, true)) {
                	String personName = doc.getItemValueString("FirstName") + " "
                    	+ doc.getItemValueString("LastName");
                    names.append(personName);
                    names.append(", ");
                }
                if (names.length() > 2) {
                	sb.append(names.substring(0, names.length() - 2) + "<br/>");
                } else {
                	sb.append("No names found.<br/>");
                }
            }
            getContext().getSessionScope().put("javaXotsOutput", sb.toString());
        } catch (Throwable t) {
        	XotsUtil.handleException(t, getContext());
            getContext().getSessionScope().put("javaXotsOutput", "ERROR");
        }
    }
}