Consider an infrastructure-based multi-band cognitive radio network (CRN) where secondary users (SUs) opportunistically access a set of sub-carriers when sensed as idle. The carrier sensing threshold which affects the access opportunities of SUs is conventionally regarded as static and treated independently from the resource allocation in the model. In this article, we study jointly the optimization of detection threshold and resource allocation with the goal of maximizing the total downlink capacity of SUs in such CRNs. The optimization problem is formulated considering three sets of variables, i.e., detection threshold, sub-carrier assignment and power allocation, with constraints on the PUs' rate loss and the power budget of the CR base station. Two schemes, referred to as offline and online algorithms respectively, are proposed to solve the optimization problem. While the offline algorithm finds the global optimal solution with high complexity, the online algorithm provides a close-to-optimal solution with much lower complexity and realtime capability. The performance of the proposed schemes is evaluated by extensive simulations and compared with the conventional static threshold selection algorithm specified in the IEEE 802.22 standard.